Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin,如何访问sqlite中的特定列属性以便添加值?_Sqlite_Xamarin_Xamarin.forms - Fatal编程技术网

Xamarin,如何访问sqlite中的特定列属性以便添加值?

Xamarin,如何访问sqlite中的特定列属性以便添加值?,sqlite,xamarin,xamarin.forms,Sqlite,Xamarin,Xamarin.forms,我知道如何读取或显示数据库中插入的所有数据,但不知道如何查询特定数据。我的数据库位于Post.cs中,它将存储日期/时间,并从用户处获取2个数据。 所以像这样: 我想做:如果(rain1和&rain2)有相同的日期。我想从rain1中添加2个数据,即21+11,并将总数保存到rain1total=32,然后rain2total将为34。我不知道从哪里开始 这里是Post.cs namespace listtoPDF.Model { //Post table, user posting drain

我知道如何读取或显示数据库中插入的所有数据,但不知道如何查询特定数据。我的数据库位于Post.cs中,它将存储日期/时间,并从用户处获取2个数据。
所以像这样:

我想做:如果(rain1和&rain2)有相同的日期。我想从rain1中添加2个数据,即21+11,并将总数保存到rain1total=32,然后rain2total将为34。我不知道从哪里开始

这里是Post.cs

namespace listtoPDF.Model
{
//Post table, user posting drainvolume
//this is the source of Binding
public class Post: INotifyPropertyChanged
{
    private double? rain1Vol;
    private double? rain2Vol;
    //from settingspage to show up in history
    string rain1lbl = Settings.Drain1LocationSettings;
    string rain2lbl = Settings.Drain2LocationSettings;      

    //ID primary key that we will autoincrement
    //These are columns ID, drain1 to 8 so 9 columns
    //These are binding source for Historypage
    [PrimaryKey, AutoIncrement]
    public int ID { get; set; }

    public static bool showLabel { get; set; }  //public class model

    public string rain1Lbl
    {
        get => rain1lbl;
        set => rain1lbl= Settings.Drain1LocationSettings;    
    }

    public string rain2Lbl
    {
        get => rain2lbl;
        set => rain2lbl= Settings.Drain2LocationSettings;    
    }

    public string CDateTime { get; set; }

    [MaxLength(3)]
    public double? rain1vol
    {
        get { return rain1Vol; }
        set
        {
            rain1Vol = value;
            RaisePropertyChanged("rain1vol");
        }
    }
    [MaxLength(3)]
    public double? rain2vol
    {
        get { return rain2Vol; }
        set
        {
            rain2Vol = value;
            RaisePropertyChanged("rain2vol");
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;

    void RaisePropertyChanged(string property)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(property));
        }

    }
}
}
以下是将列出输入日期的数据的主列表

namespace listtoPDF
{
public partial class MainPage : ContentPage
{
    List<Post> posts;


    public MainPage()
    {
        InitializeComponent();
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();
        SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation);
        conn.CreateTable<Post>();
        posts = conn.Table<Post>().ToList();
        postListView.ItemsSource = posts;     
        conn.Close();
            //right click quickwatch

    }
    void addbuttonHandle_Clicked(object sender, EventArgs args)
    {
        Navigation.PushModalAsync(new AddRainsPage());

    }

    private void GetValues()
    {
        //Initiate SQLite connection
        //Create table with class
        //Get the values in table
        //close the line
        SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation);
        conn.CreateTable<Post>();
        posts = conn.Table<Post>().ToList();
        conn.Close();
    }       
}
名称空间listtoPDF
{
公共部分类主页:ContentPage
{
列出员额;
公共主页()
{
初始化组件();
}
出现时受保护的覆盖无效()
{
base.OnAppearing();
SQLiteConnection conn=新的SQLiteConnection(App.DatabaseLocation);
conn.CreateTable();
posts=conn.Table().ToList();
postListView.ItemsSource=posts;
康涅狄格州关闭();
//右键单击“快速观察”
}
void addbuttonHandle_单击(对象发送者、事件args args)
{
PushModalAsync(newaddrainspage());
}
私有void GetValues()
{
//启动SQLite连接
//使用类创建表
//获取表中的值
//关闭线路
SQLiteConnection conn=新的SQLiteConnection(App.DatabaseLocation);
conn.CreateTable();
posts=conn.Table().ToList();
康涅狄格州关闭();
}       
}
这是一个页面,我需要在其中添加一个特定的列,这样我就可以添加与之相关联的数据

namespace listtoPDF
{
public partial class selecteddataPage : ContentPage
{
    List<Post> posts;

    public selecteddataPage()
    {
        InitializeComponent();
    }

    private void GetValues()
    {
        //Initiate SQLite connection
        //Create table with class
        //Get the values in table
        //close the line
        SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation);
        conn.CreateTable<Post>();
        posts = conn.Table<Post>().ToList();

        **if (Post.rain1 values have the same date )
          {
             totalrain1= then add data that have same date         
          }
         if (Post.rain2 values have the same date )
          {
             totalrain1= then add data that have same date         
          }**

        conn.Close();

    }
}
}
名称空间listtoPDF
{
公共部分类selecteddataPage:ContentPage
{
列出员额;
公共选择数据页()
{
初始化组件();
}
私有void GetValues()
{
//启动SQLite连接
//使用类创建表
//获取表中的值
//关闭线路
SQLiteConnection conn=新的SQLiteConnection(App.DatabaseLocation);
conn.CreateTable();
posts=conn.Table().ToList();
**如果(Post.rain1值具有相同的日期)
{
totalrain1=然后添加具有相同日期的数据
}
如果(Post.rain2值具有相同的日期)
{
totalrain1=然后添加具有相同日期的数据
}**
康涅狄格州关闭();
}
}
}

了解在SQLite中使用Group By和聚合查询。并且不要将日期时间值存储为字符串,SQLite本身就支持DateTime。或者,在从数据库获取数据后,您可以使用LINQ查询。您是对的,LINQ可能是一个更好的解决方案…从我正在阅读的内容和LINQ的教程中…@chemobrain for que对于sqlite,您可以参考MS文档。
namespace listtoPDF
{
public partial class selecteddataPage : ContentPage
{
    List<Post> posts;

    public selecteddataPage()
    {
        InitializeComponent();
    }

    private void GetValues()
    {
        //Initiate SQLite connection
        //Create table with class
        //Get the values in table
        //close the line
        SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation);
        conn.CreateTable<Post>();
        posts = conn.Table<Post>().ToList();

        **if (Post.rain1 values have the same date )
          {
             totalrain1= then add data that have same date         
          }
         if (Post.rain2 values have the same date )
          {
             totalrain1= then add data that have same date         
          }**

        conn.Close();

    }
}
}