B
Brad Markisohn
I'm trying to update a modified dataset into an Access DB. Everything seems
to work okay and I've run AcceptChanges on the dataset, but the number of
updated records is always zero! Any assistance would be greatly
appreciated. I've included the update function from my code at the end of
this message.
TIA
Brad
public int UpdateDataSet(System.Data.DataSet ds, string strTableName)
{
int iRecordsUpdated = 0; //Count of records updated
if (Connect()) //Open a connection to the DB
{
//Creat the Select Command object
System.Data.OleDb.OleDbCommand objCommand = new
System.Data.OleDb.OleDbCommand("Select * from MyUsers",Connection());
//Create the Data Adapter using the previously created command
object
System.Data.OleDb.OleDbDataAdapter DA = new
System.Data.OleDb.OleDbDataAdapter(objCommand);
//Creat the command builder object using the Data Adapter
System.Data.OleDb.OleDbCommandBuilder cb = new
System.Data.OleDb.OleDbCommandBuilder(DA);
DA.InsertCommand = cb.GetInsertCommand(); //This is the default SQL
insert command
DA.DeleteCommand = cb.GetDeleteCommand(); //This is the default SQL
delete command
DA.UpdateCommand = cb.GetUpdateCommand(); //This is the default SQL
update command
iRecordsUpdated = DA.Update(ds); //Update the database with the
modified data set
Disconnect(); //Disconnect the database
}
return (iRecordsUpdated); //Return the number of records updated
}
to work okay and I've run AcceptChanges on the dataset, but the number of
updated records is always zero! Any assistance would be greatly
appreciated. I've included the update function from my code at the end of
this message.
TIA
Brad
public int UpdateDataSet(System.Data.DataSet ds, string strTableName)
{
int iRecordsUpdated = 0; //Count of records updated
if (Connect()) //Open a connection to the DB
{
//Creat the Select Command object
System.Data.OleDb.OleDbCommand objCommand = new
System.Data.OleDb.OleDbCommand("Select * from MyUsers",Connection());
//Create the Data Adapter using the previously created command
object
System.Data.OleDb.OleDbDataAdapter DA = new
System.Data.OleDb.OleDbDataAdapter(objCommand);
//Creat the command builder object using the Data Adapter
System.Data.OleDb.OleDbCommandBuilder cb = new
System.Data.OleDb.OleDbCommandBuilder(DA);
DA.InsertCommand = cb.GetInsertCommand(); //This is the default SQL
insert command
DA.DeleteCommand = cb.GetDeleteCommand(); //This is the default SQL
delete command
DA.UpdateCommand = cb.GetUpdateCommand(); //This is the default SQL
update command
iRecordsUpdated = DA.Update(ds); //Update the database with the
modified data set
Disconnect(); //Disconnect the database
}
return (iRecordsUpdated); //Return the number of records updated
}