I watched a video tutorial and reprogrammed the same code. I have noticed that a didn´t understand, why I have to use the SqlCommandBuilder for updating a table.
SqlDataAdapter sda;
SqlCommandBuilder scb;
DataTable dt;
private void button2_Click(object sender, EventArgs e)
{
scb = new SqlCommandBuilder(sda);
sda.Update(dt);
}
I never use the variable scb. But when I comment out the scb = new SqlCommandBuilder(sda)
, then I get an error message:
"System.InvalidOperationException: A valid update command is required for an update."
Can someone explain, what function the CommandBuilder has?
In the remarks of the documentation it says:
The SqlCommandBuilder registers itself as a listener for RowUpdating events that are generated by the SqlDataAdapter specified in this property.
But I don´t understand when the CommandBuilder steps into action?