DataAdaptor.Update

  • Thread starter Thread starter Mat
  • Start date Start date
M

Mat

I'm having problems with this method.

I've a dataset with 2 tables it in, called "A" and "B". I call the
method to update one table ("A"), after which when I use
Dataset.Haschanges() I how get nothing returned, where I would of
expected the table ("B").

I've tried Update(DataSet, TableName) and Update(DataTable), and both
seem to do this.

Any ideas? I'll post my code if necessary.

Cheers,
 
Hi Mat,

Yup, show us the code.
BTW, you could first extract changes by calling DataSet.GetChanges() method
and do updates on them.
Later you should merge the results back to original dataset.
 
OK.

I have something like this. If it doesnt make sense let me know!

using (SqlTransaction trans = sqlDataConnection.BeginTransaction())
{
try
{
for (int nLoop = 0 ; nLoop < sTblNames.Length ; nLoop++ )
{
string sTableName = sTblNames[nLoop] ;
if (null != dsChanges.Tables[sTableName])
{
string insSPName = "ins" + sTableName ;
string updSPName = "upd" + sTableName ;
string delSPName = "del" + sTableName ;

String[] strInsertParams =
GetParameterList(dtaAccessor.GetConnectionString, insSPName) ;
String[] strDeleteParams =
GetParameterList(dtaAccessor.GetConnectionString, delSPName) ;
String[] strUpdateParams =
GetParameterList(dtaAccessor.GetConnectionString, updSPName) ;

SqlCommand insertCmdApplicationHeader =
SqlHelper.CreateCommand( sqlDataConnection, insSPName ,
strInsertParams) ;
SqlCommand deleteCmdApplicationHeader =
SqlHelper.CreateCommand( sqlDataConnection, delSPName ,
strDeleteParams) ;
SqlCommand updateCmdApplicationHeader =
SqlHelper.CreateCommand( sqlDataConnection, updSPName ,
strUpdateParams) ;

//Using the DAAB blocks to update the database.
//Below seems to set all the dataset update/delete/insert
modifiers, so no further updates are
//Performed on the other tables
SqlHelper.UpdateDataset(trans,
insertCmdApplicationHeader,deleteCmdApplicationHeader,updateCmdApplicationHeader,
dsChanges, sTableName);

//This works, but doesn't return the updates, as the call to
GetChanges will result in another DataTable I imagine
SqlHelper.UpdateDataset(trans,
insertCmdApplicationHeader,deleteCmdApplicationHeader,updateCmdApplicationHeader,
dsChanges.Tables[sTableName].GetChanges(DataRowState.Modified |
DataRowState.Added | DataRowState.Deleted ));

//I'm using the cascade option within the Dataset to cascade the
Primary key though the data tables.
//The initial call to inset when no Key is present will tell the
SQL Stored Proc to create a key when writing the table

}

}
trans.Commit(); //Commit transaction...
}
}


Thanks for your time...

Cheers,
 
Back
Top