James VH
James VH

Reputation: 67

Commandbuilder does not update data from datatable

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:

Upvotes: 0

Views: 216

Answers (0)

Related Questions