【发布时间】:2021-11-16 12:18:03
【问题描述】:
我正在尝试更新 sqlite 数据库中的单个记录。我知道如何插入和删除记录。我想以与下面删除单个记录类似的方式更新单个记录。这使用 linq 语句按资产 ID 获取记录。然后我想将我的数据传递给它以进行更新。
我还介绍了如何插入新记录以供参考。有没有人可以分享的例子?
删除现有记录
using (SQLiteConnection localconn = new SQLiteConnection(App.FilePath))
{
localconn.CreateTable<Road_Inspections>();
localconn.Table<Road_Inspections>().Where(x => x.Unique_ID == unique_ID).Delete();
}
插入新记录
Road_Inspections lri = new Road_Inspections()
{
ID = id,
Road_ID = Road_ID.Text.ToString(),
Asset_ID = Asset_ID.Text.ToString(),
Defect_Type = txtDefectType.Text.ToString(),
Response = txtResponse.Text.ToString(),
Inspection_Date = DateTime.Now,
};
using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
{
conn.CreateTable<Road_Inspections>();
int rowsAdded = conn.Insert(lri);
await DisplayAlert("Success", "Inspeciton Saved to Device", "OK");
}
【问题讨论】:
标签: sqlite xamarin.forms