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

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


I recently started working with UWP apps, and also came across this problem. So, how to update a row using SQLite in UWP you ask? Here ya go!

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);            });        }    }

The App.DB_PATH is the same as your 'path' variable. I realize that there are many different areas of interest in this answer, so if you have any further questions, feel free to ask.


To only update a specific set of values in a row, then executing a raw SQL query would be simpler:

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

This assumes the input you are passing to the execute statement has been cleaned.