Updating a dataset with two tables

  • Thread starter =?iso-8859-1?B?wWf6c3Q=?=
  • 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.
 
D

David Sceppa

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top