I bumped into a strange problem with one of my newest small tools.
I have one SQLite database with one Table (Journal) inside. I’m editing the data via a DataGrid which works fine. But sometimes for unapparent reason and without any exceptions it just does not write changes or new rows back to the database. That’s pretty annoying you can guess. Here’s my code:
private JournalTableAdapter adapter = new JournalTableAdapter();
private DataSetAccounting dataset = new DataSetAccounting();
public MainWindow()
{
InitializeComponent();
adapter.Connection = new SQLiteConnection("Data Source=Database/accounting.s3db");
adapter.Fill(dataset.Journal);
dataset.Journal.JournalRowChanged
+= new DataSetAccounting.JournalRowChangeEventHandler(Journal_JournalRowModified);
dataset.Journal.JournalRowDeleted
+= new DataSetAccounting.JournalRowChangeEventHandler(Journal_JournalRowModified);
dataset.Journal.TableNewRow
+= new System.Data.DataTableNewRowEventHandler(Journal_TableNewRow);
dataGridAccounting.DataContext = dataset.Journal.DefaultView;
}
void Journal_JournalRowModified(object sender, DataSetAccounting.JournalRowChangeEvent e)
{
e.Row.EndEdit();
adapter.Update(dataset.Journal);
}
void Journal_TableNewRow(object sender, System.Data.DataTableNewRowEventArgs e)
{
e.Row[2] = DateTime.Now.Date;
}
Pretty simple and easy I thought but not working like I expected =/ I don’t work with ADO.NET/SQL-Adapters a lot so please be merciful 🙂
Sincerely yours,
Nefarius
Meh, sorry, I’m stupid. I used the auto-generated version of the dataset by visual studio which compares every parameter in the WHERE-part, so ofc. he can’t find the original row in the DB. While running in VS I could reproduce the error and got an exception. Nevermind, I’ll continue reading my C#/ADO.NET book =)