473,804 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("MyD ata.xml");

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

foreach(DataRow row in ds.Tables["MainTable"].Rows
{
Console.WriteLi ne("Name = {0}", row["Name"].ToString());
...
foreach(DataRow subrow in row.GetChildRow s(MyCurrentRela tion)
{
}
}

This approach requires me to loop through the DataSet before going to the
code above, because GetChildRows requires me to know all the
MyCurrentRelati on. 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 6352
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.co m

"randy1200" <ra*******@news groups.nospamwr ote in message
news:E0******** *************** ***********@mic rosoft.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("MyD ata.xml");

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

foreach(DataRow row in ds.Tables["MainTable"].Rows
{
Console.WriteLi ne("Name = {0}", row["Name"].ToString());
...
foreach(DataRow subrow in row.GetChildRow s(MyCurrentRela tion)
{
}
}

This approach requires me to loop through the DataSet before going to the
code above, because GetChildRows requires me to know all the
MyCurrentRelati on. 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.Relatio ns
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
4761
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 two completely different systems and I've recently found duplicates! To make matters worse, the two feeds do not share a common unique key.
2
5427
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> <Image>/images/navLocationOff.jpg</Image>
6
35483
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
2067
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 do the insert, so I think I just need to figure out how to get it to loop through all the rows on the grid, and update from there.
1
5391
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 datagrid. Using the items collection just gives me the 5 rows that are displayed on the screen. Is there any way of looping through all the rows in the grid?
2
1716
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 successful at doing so, but now the following line of code does not work for looping through the records of my dataset. Is there something I need to change to now look through a Typed Dataset with just a single table? Thanks! This code used to...
7
5475
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 loop through the filtered GridView to identify the selected rows and assemble some XML to be sent to a stored proc. The problem I have is that when looping through the GridView, it doesn't
3
3732
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 retrieve the pointer to the first dataset in the list, remove it from the list, and do some high level analysis. The problem now is, how do I efficiently retrieve the pointer?
1
2005
by: Sweetiecakes | last post by:
Hello Is there an example of looping through a dataset filling an array with it? Thank you
0
9594
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10089
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9171
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6862
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
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

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.