Convert Dataset to XML

前端 未结 7 1739
野性不改
野性不改 2020-11-30 05:14

I\'ve been stuck with this problem for a few hours and can\'t seem to figure it out, so I\'m asking here :)

Alright, I\'ve got this function:

private         


        
7条回答
  •  佛祖请我去吃肉
    2020-11-30 05:35

    Write like below code part

    DataTable dt = new DataTable("MyData");
    dt.WriteXml(@Application.StartupPath + "\\DataBaseValues.xml");
    

    Or, You can convert directly the dataSet also as said by Oded like,

    private void WriteXmlToFile(DataSet thisDataSet)
    {
       if (thisDataSet == null) 
       {
          return;
       }
    
       // Create a file name to write to.
       string filename = "myXmlDoc.xml";
    
       // Create the FileStream to write with.
       System.IO.FileStream myFileStream = new System.IO.FileStream(filename, System.IO.FileMode.Create);
    
       // Create an XmlTextWriter with the fileStream.
       System.Xml.XmlTextWriter myXmlWriter = 
       new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);
    
       // Write to the file with the WriteXml method.
       thisDataSet.WriteXml(myXmlWriter);   
       myXmlWriter.Close();
    }
    

提交回复
热议问题