Reputation: 703
Scenario: I'm just trying to update my database with the changes made by the user to their information. Here is my code:
SqlCommandBuilder cb = new SqlCommandBuilder(da);
dt.Rows[0][2] = txtname.Text;
dt.Rows[0][3] = txtinterests.Text;
dt.Rows[0][4] = txtlocation.Text;
da.SelectCommand = new SqlCommand(sqlcommand, conn);
da.Update(dt);
I know its going to be something obvious, but what have I missed? There are no errors, everything compiles correctly, but nothing happens. The record remains unchanged.
Upvotes: 0
Views: 4682
Reputation: 147224
You need to define the UpdateCommand on the dataadapter (possibly the InsertCommand too).
For each Modified row in the datatable, it will fire the command you specify as the UpdateCommand.
For each New row in the datatable, it will fire the command you specify as the InsertCommand.
Check out the MSDN reference here.
Upvotes: 1