473,569 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetChildRow s("Level2");

}

}
Apr 3 '06 #1
2 2861
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.co m
"Joe" <hc******@yahoo .com> wrote in message
news:e4******** ******@TK2MSFTN GP11.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.GetChildRow s("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.GetChildRow s("l2");

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:e0******** ******@TK2MSFTN GP09.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.co m
"Joe" <hc******@yahoo .com> wrote in message
news:e4******** ******@TK2MSFTN GP11.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.GetChildRow s("Level2");

}

}


Apr 4 '06 #3

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

Similar topics

1
1199
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 syncing the dataset with an XMLdocument?
0
1179
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) via a clientid and relate the second set of tables (BOOKING AND EMPLOYEE) using an employeeid. My problem arises when there a re no records in one of...
1
1430
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 the selectedindex and querying the database and populating the childrecords in the second dropdownlist But my question is how the same can be...
4
3877
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 for each table & query. Dim tblCurrent As DataTable Dim strTableName As string For Each tblCurrent In Ds1.Tables
6
1095
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 in order in a DataGrid? Thanks in advance Geoff
1
5124
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" ds.Tables(2).TableName = "MaterialSummary" ds.Tables(3).TableName = "ItemUsage" ds.Tables(5).TableName = "UsageSummary"
9
2862
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') for file in dir: if (isdir(file)): # get the full path of the file
14
1687
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 OdbcDataAdapter = New OdbcDataAdapter(command) Dim ds As DataSet = New DataSet() adapter.SelectCommand = New OdbcCommand("select...
2
1708
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 process - so the data needs to be read in 1 record at a time then run thru the transformation that may create new data value then everything is...
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.