I have ID of Row then I will update other values.
I don't 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>();
}
Introduction to SQLite UPDATE statement First, specify the table where you want to update after the UPDATE clause. Second, set new value for each column of the table in the SET clause. Third, specify rows to update using a condition in the WHERE clause. The WHERE clause is optional.
In order to update a particular column in a table in SQL, we use the UPDATE query. The UPDATE statement in SQL is used to update the data of an existing table in the database.
SQLite-net is an open source and light weight library providing easy SQLite database storage for . NET, Mono, and Xamarin applications. This version uses SQLitePCLRaw to provide platform independent versions of SQLite. Product.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With