how to load datatable with xml

<tables>
<row>
<table_name>ticket</table_name>
<record_key>68</record_key>
</row>
<row>
<table_name>sales</table_name>
<record_key>3001</record_key>
</row>
</tables>

how can i load a datatable with above xml string


Answer this question

how to load datatable with xml

  • Nick Darnell

    How do we put the xml

    <a loan="1">

    <b Payee="A" amt="300" />

    <b Payee="B" amt="409" />

    <b Payee="C" amt="390" />

    </a>

    <a loan="2">

    <b Payee="A" amt="200" />

    <b Payee="B" amt="450" />

    <b Payee="C" amt="300" />

    </a>

    into a datatable

    SAM


  • Laxmi.

    i have the the xml stored in a string variable and not a file.. Does that datatable support xml

  • Rob Grunkemeyer

    Just to add, I'm unsure if that would be a valid xml file for the dataset, in which case you would probably have to read the xml yourself and manually create the datatable

  • tonhinbm

    you could use a StringReader to read the xml from the string into the dataset. Using your example, this works for me:

     


    string theXmlString = "<tables><row><table_name>ticket</table_name><record_key>68</record_key></row><row>";
    theXmlString += "<table_name>sales</table_name><record_key>3001</record_key></row></tables>"; //you can put these 2 lines in one, this was just for formatting issues here on the reply
    StringReader theReader = new StringReader(theXmlString);
    DataSet theDataSet = new DataSet();
    theDataSet.ReadXml(theReader);
     
    //Data will be stored in Table[0]:
    this.theDataGridView.DataSource = theDataSet.Tables[0].DefaultView;


     

     

    does this help



  • martona

    you could load the xml into a dataset:



    DataSet theDataSet = new DataSet();
    theDataSet.ReadXml("XMLfile");


    does this help



  • how to load datatable with xml