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
this:

for (int i = 0; i < adapters.Count; i++)
adapters[i].Update(tables[i]);

or this:

for (int i = 0; i < adapters.Count; i++)
adapters[i].Fill(tables[i]);

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

Thanks!

Re: Array of table adapters? by Kevin

Kevin
Tue Oct 24 21:18:59 CDT 2006

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

--
HTH,

Kevin Spencer
Microsoft MVP
Short Order Coder
http://unclechutney.blogspot.com

What You Seek Is What You Get

<mordock32@hotmail.com> wrote in message
news:1161725180.789948.295730@m7g2000cwm.googlegroups.com...
> 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
> this:
>
> for (int i = 0; i < adapters.Count; i++)
> adapters[i].Update(tables[i]);
>
> or this:
>
> for (int i = 0; i < adapters.Count; i++)
> adapters[i].Fill(tables[i]);
>
> But that doesn't seem to be feasible. Am I just missing something
> obvious?
>
> Thanks!
>



Re: Array of table adapters? by Steve

Steve
Wed Oct 25 02:24:42 CDT 2006

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[i].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
TableAdapter.

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
order...

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
Steve

<mordock32@hotmail.com> a écrit dans le message de news:
1161725180.789948.295730@m7g2000cwm.googlegroups.com...
> 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
> this:
>
> for (int i = 0; i < adapters.Count; i++)
> adapters[i].Update(tables[i]);
>
> or this:
>
> for (int i = 0; i < adapters.Count; i++)
> adapters[i].Fill(tables[i]);
>
> But that doesn't seem to be feasible. Am I just missing something
> obvious?
>
> Thanks!
>