Array of table adapters?



By the looks of it, the design of the table adapter makes it very hard
to deal with a bunch of them in a generic way. Let's say I have a typed
data set with 10 tables and relations between then. Am I supposed to
hard code every fill and update for each table? Ideally I would do

for (int i = 0; i < adapters.Count; i++)

or this:

for (int i = 0; i < adapters.Count; i++)

But that doesn't seem to be feasible. Am I just missing something


Kevin Spencer

Create your own Collection of TableAdapters. I have done this before, using
the System.Collections.ObjectModel.Collection<T> generic Collection.


Kevin Spencer
Microsoft MVP
Short Order Coder

What You Seek Is What You Get

Steve B.

Be carefull about the order of the updates...

If your DB has relations with foreign key constraints between tables, you
will have to proceed in this order :

1. Delete rows in child table that has been deleted in the child table
2. Delete rows in parent table that has been deleted in the parent table
3. Update/Insert rows in parent table that has been inserted of modified in
the parent table
4. Update/Insert rows in child table that has been inserted of modified in
the child table

Repeat steps 1 & 2 for all tables, then 3&4 for all tables...

You can use table.GetChanges(DataRowState.Deleted) and
table.GetChanges(DataRowState.Added | DataRowState.Modified) to get the
lines of the table that requires to passed to the update method of the

According this few guidelines, you can create an array (TableAdapter[]) or
collection (List<TableAdapter>) of TableAdapters. Then create a loop for
delete, and a "reverse" loop for insert/updates. The only prerequisite is
that the array or the collection need to have tableadapters in the right

A last word, do not forget that the code snippets are not quite hard to
write (take a look at "snippy"). Building in a custom business object the
whole update without making it generic but writing all updates is not a huge
operation since the concepts are quite simple...

Hope that helps

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