M
Manohar
Hi,
I am populating a dataset from a stored procedure, which returns
multiple resultsets. One of the resultset is formed with a join
condition from two tables. I am updating the fields of the respective
datatable. Then update the first table in the database using
DataAdapter.Update(). This succeeds. Subsequently, I update the
fields of the second table in the datatable and update the
respective(second) table in the database using DataAdapter.Update().
This throws the error, "Concurrency violation: the UpdateCommand
affected 0 of the expected 1 records.". Dataset.HasChanges() returns
true before each update. I give below the code.
// First Table
DataRow dr = dtOrderInfo.Rows[iSelectedRow];
dr.BeginEdit();
// Data Row changes.
....
....
dr.EndEdit();
// connect to database and execute as follows.
cnDatabaseOpen(strdbconnect);
SqlDataAdapter da = new SqlDataAdapter("Select top 0 * from
OrderDetail", cnDatabase);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
da.Update(dtOrderInfo);
da.Dispose();
cnDatabaseClose();
// Second Table
dr = null;
dr = dtOrderInfo.Rows[iSelectedRow];
dr.BeginEdit();
// Data Row changes.
....
....
dr.EndEdit();
// connect to database and execute as follows.
cnDatabaseOpen(strdbconnect);
SqlDataAdapter da = new SqlDataAdapter("Select top 0 * from Orders",
cnDatabase);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
// Following line throws error.
da.Update(dtOrderInfo);
da.Dispose();
cnDatabaseClose();
I get the error in da.Update() for the second table.
Any help would be greatly appreciated.
Thanks
Manohar
I am populating a dataset from a stored procedure, which returns
multiple resultsets. One of the resultset is formed with a join
condition from two tables. I am updating the fields of the respective
datatable. Then update the first table in the database using
DataAdapter.Update(). This succeeds. Subsequently, I update the
fields of the second table in the datatable and update the
respective(second) table in the database using DataAdapter.Update().
This throws the error, "Concurrency violation: the UpdateCommand
affected 0 of the expected 1 records.". Dataset.HasChanges() returns
true before each update. I give below the code.
// First Table
DataRow dr = dtOrderInfo.Rows[iSelectedRow];
dr.BeginEdit();
// Data Row changes.
....
....
dr.EndEdit();
// connect to database and execute as follows.
cnDatabaseOpen(strdbconnect);
SqlDataAdapter da = new SqlDataAdapter("Select top 0 * from
OrderDetail", cnDatabase);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
da.Update(dtOrderInfo);
da.Dispose();
cnDatabaseClose();
// Second Table
dr = null;
dr = dtOrderInfo.Rows[iSelectedRow];
dr.BeginEdit();
// Data Row changes.
....
....
dr.EndEdit();
// connect to database and execute as follows.
cnDatabaseOpen(strdbconnect);
SqlDataAdapter da = new SqlDataAdapter("Select top 0 * from Orders",
cnDatabase);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
// Following line throws error.
da.Update(dtOrderInfo);
da.Dispose();
cnDatabaseClose();
I get the error in da.Update() for the second table.
Any help would be greatly appreciated.
Thanks
Manohar