Mega Code Archive

 
Categories / C# Tutorial / XML
 

Create Data with DataSet and DataRow and save to xml

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");   } }