Monday, October 26, 2009

Writing XML file from dataset and Reading XML file into dataset

Writing:

OleDbConnection con = new OleDbConnection("connection string");
OleDbDataAdapter da = new OleDbDataAdapter("select * from tbl_emp", con);
DataSet ds = new DataSet();
da.Fill(ds, "emp");
ds.WriteXml("d:xmlformat.xml", XmlWriteMode.IgnoreSchema);
//this will create an xml file in "D" drive.

Reading:

DataSet ds = new DataSet();
ds.ReadXml(@"d:\xmlformat.xml");
GridView1.DataSource = ds;
GridView1.DataBind();

No comments:

Post a Comment