How to update row in sqlite.net pcl in windows 10 c #?

I have a row ID, then I update the other values.

I do not know how to update my values! My 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; } } 

other information:

  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>(); } 
+8
c # sqlite windows-10 sqlite-net
source share
2 answers

I recently started working with UWP applications, and also ran into this problem. So how to update a row using SQLite in UWP, you ask? Here you 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); }); } } 

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

+7
source share

To update only a specific set of values ​​in a row, executing a simple SQL query will be easier:

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

This assumes that the data you pass to the execution statement has been cleared.

+2
source share

All Articles