Save data in a DataSet to xml document : Xml DataSet : XML C# Examples


C# Examples » XML » Xml DataSet »

 

Save data in a DataSet to xml document









    
using  System;
using  System.IO;
using  System.Xml;
using  System.Data;

class  MainClass
{
    public  static  void  Main()
    {
        DataSet  ds  =  new  DataSet("DS");
        ds.Namespace  =  "StdNamespace";
        DataTable  stdTable  =  new  DataTable("Student");
        DataColumn  col1  =  new  DataColumn("Name");
        DataColumn  col2  =  new  DataColumn("Address");
        stdTable.Columns.Add(col1);
        stdTable.Columns.Add(col2);
        ds.Tables.Add(stdTable);

        DataRow  newRow;newRow  =  stdTable.NewRow();
        newRow["Name"]=  "M  C";
        newRow["Address"]=  "address  1";
        stdTable.Rows.Add(newRow);
        newRow  =  stdTable.NewRow();
        newRow["Name"]=  "M  G";
        newRow["Address"]=  "address1";
        stdTable.Rows.Add(newRow);
        ds.AcceptChanges();

        StreamWriter  myStreamWriter  =  new  StreamWriter(@"c:\stdData.xml");

        ds.WriteXml(myStreamWriter);
        myStreamWriter.Close();
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo XML
» Xml DataSet