473,320 Members | 1,572 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,320 software developers and data experts.

Looping Through SubTables in a DataSet

My hope is that somebody has a thought on this, or can point to toward an
article that's useful. I have the following:

DataSet ds = new DataSet();
ds.ReadXml("MyData.xml");

Each MainTable entry has subtable relations. Here's my current approach:

foreach(DataRow row in ds.Tables["MainTable"].Rows
{
Console.WriteLine("Name = {0}", row["Name"].ToString());
...
foreach(DataRow subrow in row.GetChildRows(MyCurrentRelation)
{
}
}

This approach requires me to loop through the DataSet before going to the
code above, because GetChildRows requires me to know all the
MyCurrentRelation. I can't believe I have to loop through the dataset twice.
This seems way too cheezy.

Any pointers on looping through a table with related tables in a DataSet in
one nested loop sequence?

Thanks,
--
Randy
Jul 31 '06 #1
2 6268
Randy,

Why not cycle through the Relations first, mapping them to the
parent/child tables (store info in a hashtable), and then as you cycle
through your tables/rows, you can check to see if there are relations for
the table you are on.

Hope this helps.

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

"randy1200" <ra*******@newsgroups.nospamwrote in message
news:E0**********************************@microsof t.com...
My hope is that somebody has a thought on this, or can point to toward an
article that's useful. I have the following:

DataSet ds = new DataSet();
ds.ReadXml("MyData.xml");

Each MainTable entry has subtable relations. Here's my current approach:

foreach(DataRow row in ds.Tables["MainTable"].Rows
{
Console.WriteLine("Name = {0}", row["Name"].ToString());
...
foreach(DataRow subrow in row.GetChildRows(MyCurrentRelation)
{
}
}

This approach requires me to loop through the DataSet before going to the
code above, because GetChildRows requires me to know all the
MyCurrentRelation. I can't believe I have to loop through the dataset
twice.
This seems way too cheezy.

Any pointers on looping through a table with related tables in a DataSet
in
one nested loop sequence?

Thanks,
--
Randy

Jul 31 '06 #2
Hi Randy,

I agree with Nicholas, that we can go through the DataSet.Relations
collection first. Each item is a DataRelation object. You'll be able to
fine the parent/chile table with ParentTable/ChildTable property. Please
check the following link for more information.

http://msdn2.microsoft.com/en-us/lib...ion_members.as
px

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Aug 1 '06 #3

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

Similar topics

3
by: bellefy | last post by:
Hi All, I have a fairly large table with approx 30K rows that updates every night via a cron script that automatically downloads the 2 new csv's. The problem is the files are downloaded from...
2
by: Cappy | last post by:
I am writing an XML menu structure. I have the following XML file <MenuItems> <Item> <Name>Homepa5ge</Name> <URL>/index.aspx</URL> <Alt>Return to homepage</Alt>...
6
by: Dan | last post by:
I'd like to loop through selected datagrid rows and extract specified columns from those rows. How would I do that? Thanks... Dan
5
by: Brian Conway | last post by:
I desperately need some help in coding how to have a completely ediable datagrid be able to loop through each row and insert into a database table. I am using a stored procedure in the database to...
1
by: Diva | last post by:
Hi, I have a data grid in my application. It has 20 rows and I have set the page size as 5. I have a Submit button on my form and when I click on Submit, I need to loop through the rows in the...
2
by: RCB | last post by:
I created a new Vb.NET project and used the Data Form Wizard to create a dataset and grid to view a single table from my database. Later I read an article about creating a Typed Dataset. I was...
7
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I...
3
by: Andy | last post by:
Hello, I have the following situation: Thread A is allocating a dataset, doing some low-level calculations and storing a pointer to the dataset in a std::list via push_back. Thread B should...
1
by: Sweetiecakes | last post by:
Hello Is there an example of looping through a dataset filling an array with it? Thank you
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.