none
read write into xml RRS feed

  • Question

  • DataSet dstest = new DataSet();
            DataTable dt11 = new DataTable();
            dt11.Columns.Add("id");
            dt11.Columns.Add("name");
            dt11.Rows.Add("1", "ewrw");
            dt11.Rows.Add("2", "sfdsf");
            dstest.Tables.Add(dt11);

            StreamWriter xmlDoc = new StreamWriter(@"C:\nn\SrsdXml.xml", false);
            // Apply the WriteXml method to write an XML document
            dstest.WriteXml(xmlDoc);
            xmlDoc.Close();

       // read data set
                TextReader reader1 = new StreamReader(@"C:\nn\SrXml.xml");
            DataSet dataSet = new DataSet();
            dataSet.ReadXml(reader1, XmlReadMode.InferSchema);

    it why not working pls help

    Thursday, September 21, 2017 1:08 PM

All replies

  • Hi Mohtjwari,

    Thank you for posting here.

    For your question, I test your code. You use the wrong file name of xml. And if you want to output something, you could refer to the following code.

        DataSet dstest = new DataSet();
                DataTable dt11 = new DataTable();
                dt11.Columns.Add("id");
                dt11.Columns.Add("name");
                dt11.Rows.Add("1", "ewrw");
                dt11.Rows.Add("2", "sfdsf");
                dstest.Tables.Add(dt11);
    
                StreamWriter xmlDoc = new StreamWriter(@"C:\nn\SrsdXml.xml", false);
                // Apply the WriteXml method to write an XML document
                dstest.WriteXml(xmlDoc);
                xmlDoc.Close();
    
                // read data set
                TextReader reader1 = new StreamReader(@"C:\nn\SrsdXml.xml");
                DataSet dataSet = new DataSet();
                dataSet.ReadXml(reader1, XmlReadMode.InferSchema);
                Console.WriteLine(dataSet.Tables[0]);
    

    This the xml file from your code.

    <NewDataSet>
      <Table1>
        <id>1</id>
        <name>ewrw</name>
      </Table1>
      <Table1>
        <id>2</id>
        <name>sfdsf</name>
      </Table1>
    </NewDataSet>

    And this is the output.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 21, 2017 2:47 PM
    Moderator
  • Hi Mohtjwari,

    Have you solved your problem?

    If you solved your problem, please mark the useful reply as answer. This will make answer searching in the forum and be beneficial to community members as well.

    If you have something else about this issue, please feel free to contact us.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Sunday, September 24, 2017 7:12 AM
    Moderator