Data Adapter Update Method

  • Thread starter Thread starter Yossi And Inbar
  • Start date Start date
Y

Yossi And Inbar

Hi,

I am using SqlDataAdapter and i want to do just the delete update
to delete child table and after that i want to do the InsertCommand and
etc...
So how can i choose to do Insert Or Update or Delete not with
DataAdapter.Update method..

Thanks,
Yossi
 
Yossi - I'm not sure I understand your question but let me take a stab at
it. When you call Update, the adapter looks row by row at the rowstate of
each given row and then uses the respective command for that rowstate (ie,
DeleteCommand for Deleted, Insert for Added and Update for Modified). If
you have two tables, then you need to Adapters, one for the child and one
for the parent. If you don't want to use the Update method, then you should
create your own commands and then iterate through the table, use your own
code to determine which rows you want to delete or update, and then call
your own Sql Command or Stored Procedure, passing in the relevant values for
that row. If you do this, you don't need a DataAdatper or Table Adatper, you
can just use ExecutenonQuery to accomplish what you need.

Does this answer your question? If not, please tell me a little more about
it and I'll do my best to answer it.

Cheers,

Bill
 
Use DataSet.GetChanges(DataRowState) to get a subset of what you want to
update, then call DataAdapter.Update on that subset.
eg.

// do deletions
DataSet subsetds = YourDataSet.GetChanges(DataRowState.Deleted);
YourDataAdapter.Update(subsetds);

// do insertions
subsetds = YourDataSet.GetChanges(DataRowState.Added);
YourDataAdapter.Update(subsetds);

// do modifications
subsetds = YourDataSet.GetChanges(DataRowState.Modified);
YourDataAdapter.Update(subsetds);

HTH,
Stephen
 
Back
Top