Export/Download Data into XML from Data table/Dataset

Step 1>
Connect to your databse and put a button on your form
step 2> Add given namespace 

using System.Data;
using System.Data.SqlClient;
using System.IO;

step 3>Copy and paste given code on button click event

SqlCommand cmd = new SqlCommand("select * FROM [table]", conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        dt.TableName = "Records";
        da.Fill(dt);
        DataSet dS = new DataSet();
        dS.DataSetName = "RecordSet";
        dS.Tables.Add(dt);
        StringWriter sw = new StringWriter();
        dS.WriteXml(sw, XmlWriteMode.IgnoreSchema);
        string s = sw.ToString();
       
        string attachment = "attachment; filename=test.xml";
        Response.ClearContent();
        Response.ContentType = "application/xml";
        Response.AddHeader("content-disposition", attachment);
        Response.Write(s);
        Response.End(); 

Step 4> Click on like button if its helpful for you 
Ebook Download
View all
Learn
View all