简体   繁体   English

如何在C#中更新SQLite记录的属性?

[英]How can I update a SQLite record's attributes in C#?

I'm trying to update a SQLite record's boolean "Large" attribute in my code-behind. 我正在尝试在我的代码隐藏中更新SQLite记录的boolean “ Large”属性。 I'm using the sqlite-net-pcl Nuget package in Xamarin.Forms shared project. 我在Xamarin.Forms共享项目中使用sqlite-net-pcl Nuget包。

I've figured out how to pass my record through to my method, but I can't get the attribute to update. 我已经想出了如何将记录传递给方法的方法,但是我无法更新属性。

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

When I run this I don't get any errors, but nothing happens. 运行此程序时,我没有任何错误,但是什么也没有发生。 What's the correct syntax to update a record? 更新记录的正确语法是什么? It's weirdly hard to find documentation on this subject. 很难找到有关此主题的文档。

I assume you had create dependency in platform. 我假设您在平台中创建了dependency So just open connection to SQLite according to your path. 因此,只需根据您的路径打开与SQLite连接即可。 Like what you had to do when query it back. 就像您在查询回来时要做的一样。 Like this, 像这样,

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

then use that conn to run an update on that object after you edit. 然后在编辑后使用该conn在该对象上运行更新。

conn.Update(selectedListItem);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM