如何使用c#重写SQLite表中的值

本文关键字:SQLite 何使用 重写 | 更新日期: 2023-09-27 18:17:07

例如,我有一个包含两列VariableName和Value的表。我需要编辑一些行值单元格。我使用代码:

var stateVariable = from c in db.Table<StateVariables>() where c.VariableName == "cursor" select c;
stateVariable.First().Value = cursor;
stateVariable = from c in db.Table<StateVariables>() where c.VariableName == "cursor2" select c;
stateVariable.First().Value = cursor2;
stateVariable = from c in db.Table<StateVariables>() where c.VariableName == "isForward" select c;
stateVariable.First().Value = isForward;

此代码不改变表中的值。看来我知道原因了。在这里,我试图编辑提取的数据,而不是数据库。那么,如何编辑一个值直接在SQLite表?

如何使用c#重写SQLite表中的值

从前,LINQ的SubmitChanges工作:

var recordToUpdate = (from c in db.xxx
                      where c.VariableName == "cursor"
                      select c).Single();
recordToUpdate.Value = cursor;
db.SubmitChanges();

现在,你必须使用Update来代替:

DataSet2TableAdapters.TableTestTableAdapter t = new DataSet2TableAdapters.TableTestTableAdapter();
DataSet2 ds = new DataSet2();
t.Fill(ds.TableTest); 
foreach (DataSet2.TableTestRow row in ds.TableTest.Rows)
{
    row.integer = 12345; // change value of column integer               
}
t.Update(ds2);