如何在 windows 10 C# 中更新 sqlite.net pcl 中的行?

How to Update row in sqlite.net pcl in windows 10 C#?

我有 Row 的 ID,然后我会更新其他值。

我不知道如何更新我的价值观! 我的 Table:

 class MyTable
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public string Date { get; set; }
    public string Volumes { get; set; }
    public string Price { get; set; }
}

其他信息:

 string path;
    SQLite.Net.SQLiteConnection conn;

    public updatepage()
    {
        this.InitializeComponent();
        path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "ccdb.sqlite");

        conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path);

        conn.CreateTable<MyTable>();
    }

我最近开始使用 UWP 应用程序,也遇到了这个问题。那么,如何在 UWP 中使用 SQLite 更新行?给你!

using (var dbConn = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), App.DB_PATH))
    {
        var existingUser = dbConn.Query<User>("select * from User where Id = ?", user.Id).FirstOrDefault();
        if (existingUser != null)
        {
            existingUser.Name = user.Name;
            existingUser.Email = user.Email;
            existingUser.Username = user.Username;
            existingUser.Surname = user.Surname;
            existingUser.EmployeeNumber = user.EmployeeNumber;
            existingUser.Password = user.Password;
            dbConn.RunInTransaction(() =>
            {
                dbConn.Update(existingUser);
            });
        }
    }

App.DB_PATH 与您的 'path' 变量相同。我知道这个答案有很多不同的兴趣领域,所以如果您有任何其他问题,请随时提问。

只更新一行中的一组特定值,然后执行原始 SQL 查询会更简单:

conn.Execute("UPDATE MyTable SET Price = ? Where Id = ?", 1000000, 2);

这假定您传递给执行语句的输入已被清除。