Gautam Buddha Temple Varanasi,Varanasi - Buddhist Pilgrimage

Tuesday, December 6, 2011

Export DataSet to XML File

create xml file from a dataset
This code snippet show how to export DataSet to xml file.Here we have taken data from database and fill dataset.We have taken a aspx page and a button there,after clicking the button a xml file will be created at specified location.

 public void CreateXml()  
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("usp_GetAddressDetails",con);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
StreamWriter objStreamWriter = new StreamWriter("E:\\Santosh\\Practices\\ASP\\XMLFiles\\EmpAddress.xml", false);
ds.WriteXml(objStreamWriter);
objStreamWriter.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
CreateXml();
}


Regards
Santosh Singh

2 comments:

  1. very nice article. its very useful

    You can submit your .net related article links on http://www.dotnettechy.com to get more traffic

    ReplyDelete