Create Data with DataSet and DataRow and save to xml : Xml DataSet « XML « C# / CSharp Tutorial






using System;
using System.Data;

public enum DiscountType {
  Percentage,
  Fixed
}

public class CreateData {
  public static void Main(string [] args) {
    DataSet dataSet = new DataSet();
    dataSet.ReadXmlSchema("Coupons.xsd");
    
    DataTable couponsTable = dataSet.Tables["coupons"];
    
    DataRow couponRow = couponsTable.NewRow();
    couponRow["mycode"] = "763FF";
    couponRow["amount"] = 0.5;
    couponRow["mytype"] = DiscountType.Fixed;
    couponRow["my_date"] = new DateTime(2002,12,31);
    couponsTable.Rows.Add(couponRow);
    
    dataSet.WriteXml("Coupons.xml");
  }
}








30.28.Xml DataSet
30.28.1.Fill DataSet with the data from XML
30.28.2.Load XML to DataSet
30.28.3.Save data in a DataSet to xml document
30.28.4.Create Data with DataSet and DataRow and save to xml
30.28.5.Output DataSet to Xml
30.28.6.Reading XML with DataSet