GetChildRows

  • Thread starter Christopher Weaver
  • Start date
C

Christopher Weaver

I've writtten the following (which compiles and runs). For some reason,
TaskRows is always empty.

DataRow[] TaskRows;
foreach(DataRow TaskRow in dsTaskActivities.Tables["Tasks"].Rows)
{
TaskRows = TaskRow.GetChildRows(relTaskActivities);
foreach(DataRow dr in TaskRows)
{
dsTaskActivities.Tables["Activity"].Rows.Add(dr);
}
}

I've confirmed that the DataRelation relTaskActivities in TaskActivities
works and that there is data there for it to grab; I've used this
DataRelation to fill a grid using the DA.Fill method. I'm attempting to use
GetChildRows only because I need to use DA.Fill(DataSet, int, int, string)
on the master table because there are too many records to make the download
time practicle over the web.

If anyone can tell me why GetChildRows isn't returning any rows or any other
way to accomplish the same task, I would really appreciated it. One person
suggested using a 'WHERE ... IN' query and I'm considering it, but it seems
like GetChildRows was created for this purpose.
 
Y

Yunus Emre ALPÖZEN [MCSD.NET]

First of all, u are modifying the collection which u are current iterating
on. and i could not understand what u are trying to do. How many tables are
there in your dataset 3 or 2?There should be at least three tables in your
case.

Also u want to change a row's table which row belongs to. Rows.Add will
cause an exception like "this row already belongs to a table"... You should
use ImportRow instead of add... And many questions on your question....
 
C

Christopher Weaver

First of all, u are modifying the collection which u are current iterating

I don't think so. I'm attempting to add to "Activity" while iterating
"Tasks". They are two tables within the same DataSet.

and i could not understand what u are trying to do. How many tables are
there in your dataset 3 or 2?There should be at least three tables in your
case.

I don't see why I need the third table. What I'm trying to do is iterate
through the rows in Tasks while calling GetChildRows using the DataRelation
that defines the relationship between Tasks and Activity. The purpose of
GetChildRows, as I understand it, is to retrieve just those rows that belong
in Activity given those rows that are already in Tasks.

Also u want to change a row's table which row belongs to. Rows.Add will
cause an exception like "this row already belongs to a table"... You
should use ImportRow instead of add... And many questions on your
question....

I really appreciate this insight and will investigate the usage of ImportRow
at once. Thank you very much for this.
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi,

GetChildRows does what you want, so you should concentrate in what you are
missing.
What tables does relTaskActivities link?

I hope it's not Tasks & Activity :)

you also said that you download only part of the table, of which table?
Tasks or activities?

you may miss part of the activities when you load only a part of it.

my advise would be load a part of Tasks , and nothing from Activities, when
needed just load the activities of the task you are accesing.

cheers,
 
C

Christopher Weaver

my advise would be load a part of Tasks , and nothing from Activities,
when needed just load the activities of the task you are accesing.

This is it exactly. Tasks is much too big for VPN or web access to be
practical. So I'm using DA.Fill(DataSet, int, int, string) to get a finite
set of the rows. Then, I intend to use GetChildRows with the DataRelation
relTaskActivities (yes it links Tasks and Activity) to get just those rows
from Activity that are details of the downloaded Tasks rows.

How do I get this to work!?

And, just in case you're wondering:

//Create DataRelation within dsTaskActivities
//Get the DataColumn objects from the two DataTable objects in
dsTaskActivities.
parentCol = dsTaskActivities.Tables["Tasks"].Columns["uidTask"];
childCol = dsTaskActivities.Tables["Activity"].Columns["uidTask"];
//Create a DataRelation and add it to the DataSet
relTaskActivities = new DataRelation("TaskActivities", parentCol, childCol);
dsTaskActivities.Relations.Add(relTaskActivities);

Thanks.


Ignacio Machin ( .NET/ C# MVP ) said:
hi,

GetChildRows does what you want, so you should concentrate in what you are
missing.
What tables does relTaskActivities link?

I hope it's not Tasks & Activity :)

you also said that you download only part of the table, of which table?
Tasks or activities?

you may miss part of the activities when you load only a part of it.

my advise would be load a part of Tasks , and nothing from Activities,
when needed just load the activities of the task you are accesing.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Christopher Weaver said:
I've writtten the following (which compiles and runs). For some reason,
TaskRows is always empty.

DataRow[] TaskRows;
foreach(DataRow TaskRow in dsTaskActivities.Tables["Tasks"].Rows)
{
TaskRows = TaskRow.GetChildRows(relTaskActivities);
foreach(DataRow dr in TaskRows)
{
dsTaskActivities.Tables["Activity"].Rows.Add(dr);
}
}

I've confirmed that the DataRelation relTaskActivities in TaskActivities
works and that there is data there for it to grab; I've used this
DataRelation to fill a grid using the DA.Fill method. I'm attempting to
use GetChildRows only because I need to use DA.Fill(DataSet, int, int,
string) on the master table because there are too many records to make
the download time practicle over the web.

If anyone can tell me why GetChildRows isn't returning any rows or any
other way to accomplish the same task, I would really appreciated it.
One person suggested using a 'WHERE ... IN' query and I'm considering it,
but it seems like GetChildRows was created for this purpose.
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi,

GetChildRows works with rows that you pulled already, for it to work you
have to pull ALL the rows before hand, exactly what you are trying to avoid.

Just create two queries, one to get the primary table ( or maybe a subset
only ) and other to get the childs of the selected row, this will provoke
more queries to the DB but should improve the overall performance.


cheers,
 
C

Christopher Weaver

If I understand you correctly, I should query a portion of the master table
records, then query the detail records that link to the subset of the master
rows downloaded. This makes sense, but what is the best method of
determining whether or not the detail rows have been downloaded previously
for a specific master row? My system allows the user to jump about and
change the sort order for the master table.

Thanks.
 
I

Ignacio Machin \( .NET/ C# MVP \)

no,

You query a part of the master, then WHEN needed you retrieve the part of
the secondary , this will happen when a row of the master is selected.

if later you select another master you load the new details and discard the
old ones.

cheers,
 
C

Christopher Weaver

OK. One last question.

From what you've said I gather that the user or the system must either
commit or discard any changes made to the detail rows before the user is
allowed to depart the current master row. Is that your approach?

Thanks again.
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi,

you said nothing about the data changing in the client app, if you change it
you should update the DB of course.

if the data is not changed then you have two options, either discard the
current details rows and get the new set, or just get the new set of details
rows and just append to the details table.
The later approach will make it faster if the client reselect a previously
selected master, it's already in the client table and not need to go to the
db to get an update. ( of course you will not get any update made in the DB
from the time you first got it )


cheers,
 

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