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

rad*_*din 9 c# sqlite sqlite-net windows-10

我有行ID,然后我将更新其他值.

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

 class MyTable
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public string Date { get; set; }
    public string Volumes { get; set; }
    public string Price { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

其他信息:

 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>();
    }
Run Code Online (Sandbox Code Playgroud)

ins*_*eof 9

我最近开始使用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);
            });
        }
    }
Run Code Online (Sandbox Code Playgroud)

App.DB_PATH与'path'变量相同.我意识到这个答案有很多不同的兴趣领域,所以如果你有任何进一步的问题,请随时提出.