B
BStorm
I ran into a maddening bug that I finally tracked down to Microsoft's Data
Access Blocks. It is in the SQL Helper UpdateDataSet method as follows:
Microsoft Code:
#region UpdateDataset
public static void UpdateDataset(SqlCommand insertCommand, SqlCommand
deleteCommand, SqlCommand updateCommand, DataSet dataSet, string tableName)
{
if( insertCommand == null ) throw new ArgumentNullException(
"insertCommand" );
if( deleteCommand == null ) throw new ArgumentNullException(
"deleteCommand" );
if( updateCommand == null ) throw new ArgumentNullException(
"updateCommand" );
if( tableName == null || tableName.Length == 0 ) throw new
ArgumentNullException( "tableName" );
// Create a SqlDataAdapter, and dispose of it after we are done
using (SqlDataAdapter dataAdapter = new SqlDataAdapter())
{
// Set the data adapter commands
dataAdapter.UpdateCommand = updateCommand;
dataAdapter.InsertCommand = insertCommand;
dataAdapter.DeleteCommand = deleteCommand;
// Update the dataset changes in the data source
dataAdapter.Update (dataSet, tableName);
// Commit all the changes made to the DataSet
dataSet.AcceptChanges(); // THIS IS A BUG!!!
}
}
#endregion
LAST LINE SHOULD BE:
dataSet.Tables[tableName].AcceptChanges();
The Microsoft version is committing changes to ALL tables in the dataset
prior to giving an opportuity to update the database with them. Return from
this metod shows their every table RowState as "Unchanged".
Access Blocks. It is in the SQL Helper UpdateDataSet method as follows:
Microsoft Code:
#region UpdateDataset
public static void UpdateDataset(SqlCommand insertCommand, SqlCommand
deleteCommand, SqlCommand updateCommand, DataSet dataSet, string tableName)
{
if( insertCommand == null ) throw new ArgumentNullException(
"insertCommand" );
if( deleteCommand == null ) throw new ArgumentNullException(
"deleteCommand" );
if( updateCommand == null ) throw new ArgumentNullException(
"updateCommand" );
if( tableName == null || tableName.Length == 0 ) throw new
ArgumentNullException( "tableName" );
// Create a SqlDataAdapter, and dispose of it after we are done
using (SqlDataAdapter dataAdapter = new SqlDataAdapter())
{
// Set the data adapter commands
dataAdapter.UpdateCommand = updateCommand;
dataAdapter.InsertCommand = insertCommand;
dataAdapter.DeleteCommand = deleteCommand;
// Update the dataset changes in the data source
dataAdapter.Update (dataSet, tableName);
// Commit all the changes made to the DataSet
dataSet.AcceptChanges(); // THIS IS A BUG!!!
}
}
#endregion
LAST LINE SHOULD BE:
dataSet.Tables[tableName].AcceptChanges();
The Microsoft version is committing changes to ALL tables in the dataset
prior to giving an opportuity to update the database with them. Return from
this metod shows their every table RowState as "Unchanged".