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表单选择器SelectedItem到现有SQLite表_Sqlite_Xamarin_Xamarin.forms_Picker_Selecteditem - Fatal编程技术网

Xamarin表单选择器SelectedItem到现有SQLite表

Xamarin表单选择器SelectedItem到现有SQLite表,sqlite,xamarin,xamarin.forms,picker,selecteditem,Sqlite,Xamarin,Xamarin.forms,Picker,Selecteditem,我对这一点相当陌生,在尝试将选择器SelectedItem设置为现有SQLite表时遇到了一些问题 我成功地填充了选择器(和表),没有任何问题。现在我需要用SelectedItem更新(或插入)现有单元格值 我可以设置SelectedItem值,但在尝试将其插入现有表时遇到问题。 我确实找到了一种方法来设置它,但这样做每次都会创建一个新表(正确显示SelectedItem) 在将SelectedItem放入现有表时,我是否缺少一些东西,而无需每次创建一个新表 谢谢 Xaml.cs vo

我对这一点相当陌生,在尝试将选择器SelectedItem设置为现有SQLite表时遇到了一些问题

我成功地填充了选择器(和表),没有任何问题。现在我需要用SelectedItem更新(或插入)现有单元格值

我可以设置SelectedItem值,但在尝试将其插入现有表时遇到问题。 我确实找到了一种方法来设置它,但这样做每次都会创建一个新表(正确显示SelectedItem)

在将SelectedItem放入现有表时,我是否缺少一些东西,而无需每次创建一个新表

谢谢

Xaml.cs

     void TermGoClicked(object sender, EventArgs e)
    {
        //local database where populated table is stored
        using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
        {
            //sets the Picker SelectedItem index
            var pickerItem = termPicker.Items[termPicker.SelectedIndex];

            //created new Courses table
            var courses = new Courses();

            //sets the PickerItem column with the Selected Item on newly created table.
            courses.PickerItem = pickerItem;
            conn.Update(courses);

            Navigation.PushAsync(new TermPage());
        }

    }
Xaml


我明白了

我曾尝试使用访问现有课程表

    var courses = conn.Table<Courses>;
var课程=连接表;
但它找不到PickerItem列。所以我把它拿走了。不过,我补充说

    var courses = conn.Table<Courses>.FirstOrDefault();
var courses=conn.Table.FirstOrDefault();
而且它工作得很好


谢谢@Jason为我指明了正确的方向

您需要首先从数据库中检索现有项,然后更新其属性,然后执行数据库更新。如果每次只创建一个新的
Courses
记录,那么它当然会在数据库中插入一个新行。
    var courses = conn.Table<Courses>.FirstOrDefault();