Load XML into typed dataset

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

Guest

Hi. I have a typed dataset which defines several tables and the relationships between them. Most of the tables will be populated from my database and this is working already. However one table will be populated from an XML document. Any pointers as to how I do this

Thank

KH
 
Hi
you can read it in a normal dataset "not typed" by using the readXml
method which will create a table with the name of your xml complex element
in the dataset


so ,if your xml look like so
<person>
<name> first last </name>
<age> 30 </age>
<sex> M </sex>
</person>
<person>
<name> fname Lname </name>
<age> 30 </age>
<sex> F </sex>
</person>
---if the file is on root C for example, then you can read it in a dataset
this way
DataSet k = new DataSet();
k.ReadXml("c:\\file.xml");
// the dataset now has a table with the name person that
contains all your data , so to get the age of person in second row
string name =
k.Tables["person"][1]["age"].ToStriing();
now , you can fill the data into the table of your typed dataset form the
table you have into the untyped one . hope that would help
 
Back
Top