K
kwgainey
Hi folks,
I have some code which takes a datatable, makes some changes to the
rows, and uses the dataadapter.update(datatable) command to write the
changes back to the db. When I look at the changed rows in the
datatable (and export them out to xml), the updated fields are present.
When I capture the UpdatingEvent thrown by the dataadapter, the
updatecommand is missing one of my parameters. Because of this, the
changes don't make it into the database.
What would cause a parameter to NOT be included in the update command?
The field does allow nulls and every other field in the table is
updating fine, so I know the transaction is committing. Thanks in
advance for your help!
-Kevin
Code (some of the variable declarations moved for brevity):
public void updateProcedure(ref SqlTransaction tran)
//transaction object passed into this method
//create the datatable to be updated and dataadapter
updateDataAdapter = new SqlDataAdapter();
updateDataAdapter.SelectCommand = new SqlCommand(sqlStatement, cn,
tran);
SqlCommandBuilder custCB = new SQLCommandBuilder(updateDataAdapter);
DataTable updateTable = new DataTable();
updateDataAdapter.Fill(updateTable)
//call method to make some changes to the updateTable
//now that the table has been update, write to xml to confirm changes
DataTable xDataTable = updateTable.GetChanges();
WriteXMLToFile(xDataTable, "c:\temp\DataTableChanges.xml");
//perform the update
//add update handlers
updateDataAdapter.RowUpdating += new
SqlRowUpdatingEventHandler(OnRowUpdating);
updateDataAdapter.RowUpdated += new SqlRowUpdatedEventHandler(
OnRowUpdated );
//call the update method
updateDataAdapter.Update(updateTable);
//remove handlers
updateDataAdapter.RowUpdating -= new
SqlRowUpdatingEventHandler(OnRowUpdating);
updateDataAdapter.RowUpdated -= new SqlRowUpdatedEventHandler(
OnRowUpdated );
//this method exits and the transaction object which was passed in is
committed.
I have some code which takes a datatable, makes some changes to the
rows, and uses the dataadapter.update(datatable) command to write the
changes back to the db. When I look at the changed rows in the
datatable (and export them out to xml), the updated fields are present.
When I capture the UpdatingEvent thrown by the dataadapter, the
updatecommand is missing one of my parameters. Because of this, the
changes don't make it into the database.
What would cause a parameter to NOT be included in the update command?
The field does allow nulls and every other field in the table is
updating fine, so I know the transaction is committing. Thanks in
advance for your help!
-Kevin
Code (some of the variable declarations moved for brevity):
public void updateProcedure(ref SqlTransaction tran)
//transaction object passed into this method
//create the datatable to be updated and dataadapter
updateDataAdapter = new SqlDataAdapter();
updateDataAdapter.SelectCommand = new SqlCommand(sqlStatement, cn,
tran);
SqlCommandBuilder custCB = new SQLCommandBuilder(updateDataAdapter);
DataTable updateTable = new DataTable();
updateDataAdapter.Fill(updateTable)
//call method to make some changes to the updateTable
//now that the table has been update, write to xml to confirm changes
DataTable xDataTable = updateTable.GetChanges();
WriteXMLToFile(xDataTable, "c:\temp\DataTableChanges.xml");
//perform the update
//add update handlers
updateDataAdapter.RowUpdating += new
SqlRowUpdatingEventHandler(OnRowUpdating);
updateDataAdapter.RowUpdated += new SqlRowUpdatedEventHandler(
OnRowUpdated );
//call the update method
updateDataAdapter.Update(updateTable);
//remove handlers
updateDataAdapter.RowUpdating -= new
SqlRowUpdatingEventHandler(OnRowUpdating);
updateDataAdapter.RowUpdated -= new SqlRowUpdatedEventHandler(
OnRowUpdated );
//this method exits and the transaction object which was passed in is
committed.