I have the following code in my WPF project:
string query2 = "SELECT * FROM Anamnese_VMBO";
string connectionstring = <Removed string for privacy >
IDbConnection con1 = new OleDbConnection(connectionstring);
con1.Open();
OleDbCommand dbCommand = new OleDbCommand(query2, (OleDbConnection)con1);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(dbCommand);
OleDbCommandBuilder cb = new OleDbCommandBuilder(dataAdapter);
cb.GetDeleteCommand(true);
cb.GetInsertCommand(true);
cb.GetUpdateCommand(true);
dataAdapter.Fill(this.dt1);
dt1.Merge(dt);
dt1.GetChanges();
dataAdapter.Update(dt1);
dt1.AcceptChanges();
Grid.ItemsSource = dt1.DefaultView;
con1.Close();
As you can see in the code, I am merging 2 data tables together and then I am performing the update command builder. When I run the code, I can see that my 2 data tables have the exact values i need but when I check my database, nothing updated.
Some things I tested:
- Regular commandtext works when I try to insert static data. I ran a test where I manually gave the OleDBCommand an insert statement, and it worked.
- the column names do not have special characters or are in any way invalid.
- All tables in my databases have primary keys.
- The table i merge with has the exact same column names.
- I have to use the command builder because there are too many columns to manually write.