Updating a dataset with two tables

  • Thread starter Thread starter =?iso-8859-1?B?wWf6c3Q=?=
  • Start date Start date
?

=?iso-8859-1?B?wWf6c3Q=?=

Hi

I'm using a webservice to update a datset which contains
two tables. There is a simple Category-Item refrence
between the tables, that is there is a foreign key from
Category to the Item table. Because of that, if I add a
item the refrenced category has to exist.

How can I control in what order the webservice executes
the DELTE/INSERT commands?

1)If I'am adding a new category and items which refrence
the new category the webservice should first add the
category and then the items.
2) If I'am deleteing a category the webservice should
first delete the items for that category and then the
category?!?

Thanks, Ágúst V.
 
The simplest way to submit pending changes from multiple
related tables is to use DataAdapter.Update in conjunction with
DataTable.Select. There's an overloaded DataTable.Select method
that lets you filter rows based on their RowState. Using this
method lets you submit parent inserts before child inserts, and
child deletes before parent deletes.

Submit pending deletions from in a "bottom up" approach:
ChildAdapter.Update(ChildTable.Select("", "",
DataViewRowState.Deleted))
ParentAdapter.Update(ParentTable.Select("", "",
DataViewRowState.Deleted))
...

Then submit inserts and updates (which are the only changes that
remain) in a "top down" approach:
ParentAdapter.Update(ParentTable)
ChildAdapter.Update(ChildTable)
...

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.
 
Back
Top