Connecting Tech Pros Worldwide Forums | Help | Site Map

Walk thru all relations in dataset

Joe
Guest
 
Posts: n/a
#1: Apr 3 '06
Hi

I have a dataset with 3 tables and 2 relations
Is there a way to when I am at 1 row to tell if there is a relation on that
row ???
I have the code hardcoded but try to make it work if the # of tables and
#relations increase or decrease
So I can just pass any dataset and walk thru the rows??

Thanks

for (int p = 0; p < ds.Tables[1].Rows.Count; p++)

{

//Get Childs rows of parent

DataRow [] rows = ds.Tables[1].Rows[p].GetChildRows("Level1");

for ( int t = 0; t < rows.Length; t++)

{

DataRow drc = rows[t]; //Current row


//Get Childs rows of parent

DataRow [] childrows = drc.GetChildRows("Level2");

}

}



Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
#2: Apr 3 '06

re: Walk thru all relations in dataset


Joe,

What I would do is before you loop through the rows in a table, cycle
through the relations to find out which one uses your table as the parent
table. Store those in a list.

Then, through each row, you can find the child rows by calling
GetChildRows on each row for the relation for each relation you know your
current table is a parent of.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com


"Joe" <hchs1977@yahoo.com> wrote in message
news:e4uXuQ2VGHA.2760@TK2MSFTNGP11.phx.gbl...[color=blue]
> Hi
>
> I have a dataset with 3 tables and 2 relations
> Is there a way to when I am at 1 row to tell if there is a relation on
> that row ???
> I have the code hardcoded but try to make it work if the # of tables and
> #relations increase or decrease
> So I can just pass any dataset and walk thru the rows??
>
> Thanks
>
> for (int p = 0; p < ds.Tables[1].Rows.Count; p++)
>
> {
>
> //Get Childs rows of parent
>
> DataRow [] rows = ds.Tables[1].Rows[p].GetChildRows("Level1");
>
> for ( int t = 0; t < rows.Length; t++)
>
> {
>
> DataRow drc = rows[t]; //Current row
>
>
> //Get Childs rows of parent
>
> DataRow [] childrows = drc.GetChildRows("Level2");
>
> }
>
> }
>
>[/color]


Joe
Guest
 
Posts: n/a
#3: Apr 4 '06

re: Walk thru all relations in dataset


Hi Nicholas

Thanks

The problem is that the relation is at different levels
This is a dataset with 3 tables

table1 shows 2 relations l1 and l2
From Table1 I get a row collection from the parent row with relation
From 1 row from collection I get another collectiom with another relation

The Tables are all cascading
I am starting at the top level maybe I should start at the bottom???

I am submitting another question to the group because I am not sure if this
is easier or
xml and xpath if I use the xsd - this dataset can have any number of fields
and relations
and I get it down stream

Thanks


DataRow [] rows = ds.Tables[1].Rows[p].GetChildRows("l1");
for ( int t = 0; t < rows.Length; t++)

{

DataRow drc = rows[t]; //Current row

DataRow [] childrows = drc.GetChildRows("l2");



"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in
message news:e0oGap2VGHA.5692@TK2MSFTNGP09.phx.gbl...[color=blue]
> Joe,
>
> What I would do is before you loop through the rows in a table, cycle
> through the relations to find out which one uses your table as the parent
> table. Store those in a list.
>
> Then, through each row, you can find the child rows by calling
> GetChildRows on each row for the relation for each relation you know your
> current table is a parent of.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mvp@spam.guard.caspershouse.com
>
>
> "Joe" <hchs1977@yahoo.com> wrote in message
> news:e4uXuQ2VGHA.2760@TK2MSFTNGP11.phx.gbl...[color=green]
>> Hi
>>
>> I have a dataset with 3 tables and 2 relations
>> Is there a way to when I am at 1 row to tell if there is a relation on
>> that row ???
>> I have the code hardcoded but try to make it work if the # of tables and
>> #relations increase or decrease
>> So I can just pass any dataset and walk thru the rows??
>>
>> Thanks
>>
>> for (int p = 0; p < ds.Tables[1].Rows.Count; p++)
>>
>> {
>>
>> //Get Childs rows of parent
>>
>> DataRow [] rows = ds.Tables[1].Rows[p].GetChildRows("Level1");
>>
>> for ( int t = 0; t < rows.Length; t++)
>>
>> {
>>
>> DataRow drc = rows[t]; //Current row
>>
>>
>> //Get Childs rows of parent
>>
>> DataRow [] childrows = drc.GetChildRows("Level2");
>>
>> }
>>
>> }
>>
>>[/color]
>
>[/color]


Closed Thread