Access nested child data within a dataset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone tell me how to access the "nested child" data of a specific
parent from within a dataset? I read an XML file into a dataset with its
schema and want to access the child nested data. The one I access is
identified by a unique value within the parent data. In the below snippet,
I'll loop through the LanguageData64 entries and find the Code (e.g., 00).
From there are want to access the PartNumbers and return a reference to that
PartNumbers table to access its entries.

A snippet of the XML file is here.

<Languages64Bit>
<LanguageData64>
<Abbr>B2</Abbr>
<Code>B2</Code>
<MUI>false</MUI>
<Language>Global</Language>
<PartNumbers>
<PartNumber1>35-01</PartNumber1>
<PartNumber2>35-02</PartNumber2>
</PartNumbers>
<Description>a description</Description>
</LanguageData64>
<LanguageData64>
<Abbr>US</Abbr>
<Code>00</Code>
<MUI>false</MUI>
<Language>English</Language>
<PartNumbers>
<PartNumber1>33-01</PartNumber1>
<PartNumber2>33-02</PartNumber2>
</PartNumbers>
<Description>another description</Description>
</LanguageData64>
</Languages64Bit>
 
Hi Steve,

To access child rows from your Xml file, you need to create schema for the
DataSet in order to let the DataSet get relation information. Here are the
steps:

1. Add the xml file to project.
2. Select Create Schema button to create the schema.
3. Add the schema file to your project.
4. When creating the DataSet, load schema with DataSet.ReadXmlSchema.
5. Load data with DataSet.ReadXml.
6. You can now get child rows with DataRow.GetChildRows method. Here is an
example.

DataRow[] dr =
ds.Tables["LanguageData64"].Rows[0].GetChildRows("LanguageData64_PartNumbers
");

HTH.

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
This was exactly what I needed to get past the barrier I was against. Thank
you very much!!!!
 
You're welcome!

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

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