DataRelation and Fill(ds, int, int, dt)

  • Thread starter Christopher Weaver
  • Start date
C

Christopher Weaver

I've filled a DataSet with two tables then established a DataRelation; all
is well because the backend includes RI rules that ensure that no record on
the detail side will be without a master record. However, there are too
many records on the master side for an efficient use of the app over the web
via website or VPN. So, I've implemented Fill(ds, int, int, dt) such that I
control how many records are downloaded. Now the problem is that the detail
table is left with many records that have no corresponding records on the
master side and the DataRelation won't take.

My question is what is the best method of fetching only the related records?
I've seen GetChildRows, but I'm hoping that there is a 'built-in' way of
doing this through the DataAdapter. If not, then my question is do I use
this or something like it:

DataRow[] arrRows;
foreach(DataRow masterRow in masterTable.Rows){
arrRows = masterRow.GetChildRows(myRelation);
....
}

If so, how do I get arrRows into the correct Table of the DataSet? Is
foreach with the Add method of the DataRowCollection class the way to go
with this?

Thanks.
 
M

Miha Markic [MVP C#]

Hi Christopher,

I would collect all master table primary key values, create a sql select
statement for detail rows with something like WHERE master.primarykey IN (my
values) and fill only these detail rows.
 
C

Christopher Weaver

This is good. Thanks.



Miha Markic said:
Hi Christopher,

I would collect all master table primary key values, create a sql select
statement for detail rows with something like WHERE master.primarykey IN
(my values) and fill only these detail rows.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

Christopher Weaver said:
I've filled a DataSet with two tables then established a DataRelation;
all is well because the backend includes RI rules that ensure that no
record on the detail side will be without a master record. However,
there are too many records on the master side for an efficient use of the
app over the web via website or VPN. So, I've implemented Fill(ds, int,
int, dt) such that I control how many records are downloaded. Now the
problem is that the detail table is left with many records that have no
corresponding records on the master side and the DataRelation won't take.

My question is what is the best method of fetching only the related
records? I've seen GetChildRows, but I'm hoping that there is a
'built-in' way of doing this through the DataAdapter. If not, then my
question is do I use this or something like it:

DataRow[] arrRows;
foreach(DataRow masterRow in masterTable.Rows){
arrRows = masterRow.GetChildRows(myRelation);
....
}

If so, how do I get arrRows into the correct Table of the DataSet? Is
foreach with the Add method of the DataRowCollection class the way to go
with this?

Thanks.
 

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