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
C# 如何在windows 10 C中更新sqlite.net pcl中的行?_C#_Sqlite_Windows 10_Sqlite Net - Fatal编程技术网

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

C# 如何在windows 10 C中更新sqlite.net pcl中的行?,c#,sqlite,windows-10,sqlite-net,C#,Sqlite,Windows 10,Sqlite Net,我有行的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; } } 其他资料: string p

我有行的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; }
}
其他资料:

 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”变量相同。我意识到这个答案中有许多不同的方面值得关注,因此如果您有任何进一步的问题,请随时提问。

要仅更新一行中的特定值集,则执行原始SQL查询会更简单:

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

这假设您传递给execute语句的输入已被清除。

请参考本文,尽管它说的是通用应用程序,但我认为它也适用于windows 10应用程序。然后我需要立即将其更新为viewmodel对象吗?有什么好办法吗?