Can't get parent child relationship set up within DataSet

B

Brad Wood

I'm just trying to get a simple parent-child example working using the
designer.

I've done this:
- Added 2 tables with columns to a DataSet.
- Added a relationship between the 2 tables to the DataSet.
- Now I assume I need to set table mappings in my DataAdapter (when I
run the project all of the returned data is loaded into only one of my
data tables).
- When I open the Table Mappings dialog and check "Use a dataset to
suggest table and column names", the corresponding drop list reports,
"(no datasets in project)".

What do I need to do to make my DataAdapter recognize my Dataset?
 
B

Bart Mermuys

Hi,

Brad Wood said:
I'm just trying to get a simple parent-child example working using the
designer.

I've done this:
- Added 2 tables with columns to a DataSet.
- Added a relationship between the 2 tables to the DataSet.
- Now I assume I need to set table mappings in my DataAdapter (when I run
the project all of the returned data is loaded into only one of my data
tables).

Usually one uses two DataAdapter's, one to fill each DataTable. You can
get away with one DataAdapter and one Fill only if your query returns two
tables. A single join query won't work to fill both DataTable's.

HTH,
Greetings
 
B

Brad Wood

So the only way to accomplish this is to query the parent table and then
iterate through it's records making a query on each record to the child
table? That sounds impossibly inefficient...
 
B

Bart Mermuys

Hi,

Brad Wood said:
So the only way to accomplish this is to query the parent table and then
iterate through it's records making a query on each record to the child
table?

Depends if you want a filter on the parent table or not, if not then just
get all parent records and all child records. A DataRelation relates parent
and child DataRow's after they are loaded.

If you put a filter on the parent table you will have to put the same filter
on the child table, eg.

- SELECT * FROM orders WHERE cust_id = 10;

- SELECT * FROM orders_detail WHERE order_id IN
(SELECT order_id FROM orders WHERE cust_id=10);

NET has no way to read related rows from a database but it can associate
DataRow's with child DataRow's using DataRelation's.

HTH,
Greetings
 
B

Brad Wood

I can't get all parent and child records because there are way too many.

So just to be clear - I just want a relationship between one parent and
many children. I was hoping to be able to have all of the parent's
columns in one Table and all the child's in another, but it seems that's
impossible w/o either
- Making multiple queries or
- Loading all rows
 
B

Bart Mermuys

Hi,

Brad Wood said:
I can't get all parent and child records because there are way too many.

So just to be clear - I just want a relationship between one parent and
many children. I was hoping to be able to have all of the parent's
columns in one Table and all the child's in another, but it seems that's
impossible w/o either
- Making multiple queries or
- Loading all rows

It doesn't matter if you want all rows or not you always need a query to
fill each DataTable unless you use a batch query or a stored prodecure that
returns a resultset for each DataTable.

If you don't want to load all parent and child data then use queries like in
my previous post.

HTH,
Greetings
 

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