Hi BRUCE,
The following code is not necessary.
dap.UpdateCommand = cmd.GetUpdateCommand();
dap.DeleteCommand = cmd.GetDeleteCommand();
dap.InsertCommand = cmd.GetInsertCommand();
When you create SqlCommandBuilder (SqlCommandBuilder cmd = new SqlCommandBuilder(dap);), it already does the work.
I don’t know what the purpose for this code is.
int cn = dsServer.Tables[0].Rows.Count - 1;
for (int i = 0; i <= cn; i++)
{
DataRow dr = dsServer.Tables[0].Rows[i];
if (dr.RowState == DataRowState.Unchanged)
{
dr.SetAdded();
}
else
if (dr.RowState == DataRowState.Added)
{
dr.AcceptChanges();
dr.Delete();
}
}
Based on my understanding, you just need to call “int eff=dap.Update(dsServer.Tables[0]);”, it will do all the insert, update, delete work for you. Could you please test my suggestion and tell me the result?
If I misunderstood you, please feel free to tell me.
Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the
All-In-One Code Framework!