views:

21

answers:

1

I'm using table adapters and datasets in .NET (version 2.0).

I have two tables like this:

Table1
------
...
TypeId

Table2
------
Id
Name

where Table1.TypeId is linked to Table2.Id.

I've strongly generated these types by using the wizard so now I can do things like this:

Table1Adapter adapter = new Table1Adapter();
Table1DataSet data = adapter.GetData();

foreach(Table1Row row in data) { ... }
// Can now iterate through and display the data

This all works fine. But now I also want the data from Table2. I have noticed that in row there is generated field Table2Row which seems ideal but it is set to null. How do I populate this dataset properly?

A: 

Each DataTable in Typed-Dataset has its own TableAdapter. So you'll have to the same step for each DataTable in the dataset.

There does not exists any api that lets you do this auto-fill of the entire typed-dataset or no such code is generated within typed-dataset that supports this. It is also difficult to do this because TableAdapters do not have a common base-class that can let you do this.

If you really need to do this, you'll have to maintain a collection of DataTable type-names and TableAdapter type-names and iterate over the collection to perform the dataset fill.

So I recommend to fill dataset for each table in 'hard-code' manner.

this. __curious_geek
Alright, and what is the best way to merge this data into my parent data table?
DanDan
Create instances of each TableAdapter and fill the Dataset. You won't be to fill entire dataset at once, you must do it table-by-table.
this. __curious_geek
So if I have two adapters and two datasets, how do I enforce the relationship? I'd really like to do something like row.typerow.Name
DanDan
Relationships will be enforced but you won't be able to access them relationally.
this. __curious_geek