Reputation: 35703
What is wrong with my code? Updates are not saved to the db.
SQLiteConnection connection = new SQLiteConnection(string.Format(@"Data Source={0}\statistik.s3db",Application.StartupPath));
connection.Open();
SQLiteDataAdapter db = new SQLiteDataAdapter("SELECT * FROM log WHERE Typ=1", connection);
DataSet ds = new DataSet();
db.Fill(ds);
SQLiteCommandBuilder builder = new SQLiteCommandBuilder(db);
foreach (DataRow row in ds.Tables[0].Rows)
{
row["Message"] = "myupdatedmessage"; // IS NOT SAVED!
}
ds.AcceptChanges();
db.UpdateCommand = builder.GetUpdateCommand();
db.Update(ds.Tables[0]);
connection.Close();
Upvotes: 0
Views: 925
Reputation: 216323
It is a common error. (Probably neither Microsoft is immune to the naming problem misunderstanding)
You need to remove this line
ds.AcceptChanges();
The call to AcceptChanges sets every row in your DataSet tables to Unchanged and after that, the Update method cannot find anything to update.
A part from this please note that Application.StartupPath
, when debugging, points to the BIN\DEBUG folder (or x86 variant) and thus there is the possibility that you are writing in a different database file than the one that you are looking at (the one in the project folder?).
Upvotes: 2