473,413 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Walk thru all relations in dataset

Joe
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");

}

}
Apr 3 '06 #1
2 2838
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]
- mv*@spam.guard.caspershouse.com
"Joe" <hc******@yahoo.com> wrote in message
news:e4**************@TK2MSFTNGP11.phx.gbl...
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");

}

}

Apr 3 '06 #2
Joe
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]" <mv*@spam.guard.caspershouse.com> wrote in
message news:e0**************@TK2MSFTNGP09.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com
"Joe" <hc******@yahoo.com> wrote in message
news:e4**************@TK2MSFTNGP11.phx.gbl...
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");

}

}


Apr 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: womber | last post by:
What do you think is the best design approach when your trying to get nested XML results from dataSet.GetXML. Define the relations in the dataset or apply an XSLT stylesheet to nest the results by...
0
by: Joe Van Meer | last post by:
Hi all, I have a question regarding data relations within a data set. Say I have 3 tables named CLIENT, BOOKING and EMPLOYEE and I wanted to relate the first two tables (CLIENT AND BOOKING)...
1
by: Ravi | last post by:
I am trying to represent master-detail records from a database The general logic will be populating the first dropdownlist with the master records and on change of the first dropdownlis getting...
4
by: What-a-Tool | last post by:
I am trying to write a program that will take all the members of a data base, add them to a tree, with all child relations as sub-nodes. I am having a problem getting the parent child relations...
6
by: Geoff Jones | last post by:
Hi I have two tables to which I have created a one-to-many relationship. How do I sort the result of the relationship? For example, if one column contains dates, how do I display in the dates...
1
by: Randy Fraser | last post by:
How do I create a relationship on muliple columns in an untyped dataset. Why does this not work. da.Fill(ds) ds.Tables(0).TableName = "DesignSummary" ds.Tables(1).TableName = "FormulaSummary"...
9
by: silverburgh.meryl | last post by:
i am trying to use python to walk thru each subdirectory from a top directory. Here is my script: savedPagesDirectory = "/home/meryl/saved_pages/data" dir=open(savedPagesDirectory, 'r') ...
14
by: kjewell23 | last post by:
Hi. I have the code working just fine except all the data isn't coming up with the ds.relations code. Could you see what I'm doing wrong or what else I need to add. Code down below Dim adapter As...
2
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Have a complex process where I need to Import a large amount of data then run some transformations on this data then import into DataBase. The transformation involves multiple fields and multiple...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.