【问题标题】:How can I update a SQLite record's attributes in C#?如何在 C# 中更新 SQLite 记录的属性?
【发布时间】:2018-05-29 09:47:29
【问题描述】:

我正在尝试在我的代码隐藏中更新SQLite 记录的boolean“大”属性。我在Xamarin.Forms 共享项目中使用sqlite-net-pcl Nuget 包。

我已经知道如何将我的记录传递给我的方法,但我无法更新属性。

public async void PutBack(object sender, ItemTappedEventArgs e)
{
    var selectedListItem = e.Item as ListItem;
    selectedListItem.Large = false
    ...
}

当我运行它时,我没有收到任何错误,但没有任何反应。更新记录的正确语法是什么?很难找到关于这个主题的文档。

【问题讨论】:

    标签: c# sqlite xamarin xamarin.forms sqlite-net-pcl


    【解决方案1】:

    我假设您在平台中创建了dependency。因此,只需根据您的路径打开与SQLite 的连接即可。就像您在查询时必须做的一样。像这样,

    var platform = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();   
    var conn = new SQLiteConnection(platform, path);
    

    然后在编辑后使用该conn 对该对象运行更新。

    conn.Update(selectedListItem);
    

    【讨论】:

      猜你喜欢
      • 2021-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-23
      • 1970-01-01
      • 2021-11-15
      • 2023-03-06
      • 2018-06-09
      相关资源
      最近更新 更多