Navigate a DataSet/DataTable

  • Thread starter Thread starter Carl Lindmark
  • Start date Start date
C

Carl Lindmark

Hello,

I am having trouble understanding how to navigate a DataSet table... - maybe
someone can steer me in the right direction?

Say you've read an XML document into a DataSet ("myDataSet") and then filled
a DataTable by doing: myDataSet.Tables["situation"];
and the XML looks this way:
....
<situation>
<objectID>123</objectId>
<validityPeriod>
<start>2004-10-16T06:00:00+02:00</start>
<end>2004-10-18T15:00:00+02:00</end>
</validityPeriod>
....
</situation>
....

Now, the DataTable is filled nicely and I can access the "objectId" value
easily, but I just don't understand how I can go from "situation" to
"validityPeriod" and then on to "start" and "end".

I THINK I managed to get to the "start" and "end" values directly, by using
"GetChildRows" somehow - but the way I did that, I couldn't make sure that
the "start" and "end" I found were actually children of "validityPeriod",
which I have to be sure of.

Could anyone help me navigate this DataTable?
Thanks in advance!

Sincerely,
Carl Lindmark
 
Hello Carl,

The GetChildRows is the way to go, and as far as I remember the DataSet XML
reading logic *will* infer a child validityPeriod table from the XML
structure you have.
You can simply check that by setting a breakpoint where you retrieve child
rows, adding a variable containing a reference to the child row to the Watch
window and drilling down it's Table property.
 
Hi Dmytro,

Thank you very much for your pointers!
I had not realized that the "validityPeriod" XML tag would be a TABLE - I
thought it would just be a sub ROW... But now I'm beginning to understand
how these datasets and datatables work. Thank you very much!

/Carl



Dmytro Lapshyn said:
Hello Carl,

The GetChildRows is the way to go, and as far as I remember the DataSet XML
reading logic *will* infer a child validityPeriod table from the XML
structure you have.
You can simply check that by setting a breakpoint where you retrieve child
rows, adding a variable containing a reference to the child row to the Watch
window and drilling down it's Table property.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


Carl Lindmark said:
Hello,

I am having trouble understanding how to navigate a DataSet table... -
maybe
someone can steer me in the right direction?

Say you've read an XML document into a DataSet ("myDataSet") and then
filled
a DataTable by doing: myDataSet.Tables["situation"];
and the XML looks this way:
...
<situation>
<objectID>123</objectId>
<validityPeriod>
<start>2004-10-16T06:00:00+02:00</start>
<end>2004-10-18T15:00:00+02:00</end>
</validityPeriod>
...
</situation>
...

Now, the DataTable is filled nicely and I can access the "objectId" value
easily, but I just don't understand how I can go from "situation" to
"validityPeriod" and then on to "start" and "end".

I THINK I managed to get to the "start" and "end" values directly, by
using
"GetChildRows" somehow - but the way I did that, I couldn't make sure that
the "start" and "end" I found were actually children of "validityPeriod",
which I have to be sure of.

Could anyone help me navigate this DataTable?
Thanks in advance!

Sincerely,
Carl Lindmark
 
Back
Top