Creating XML file from the Database table
Description:
The below code is used to create a xml document from
the table of the database.
Code Behind:
SqlConnection con = new SqlConnection();
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindtoXml();
}
}
private void BindtoXml()
{
con.ConnectionString = "server=10.104.10.145;database=Northwind;user id=sa;password=sa";
SqlDataAdapter da = new SqlDataAdapter("Select * from customers", con);
da.Fill(ds, "customers");
if (ds.Tables["customers"].Rows.Count > 0)
{
ds.WriteXml("D:\\CustDataNewfile.Xml");
ds.WriteXmlSchema("D:\\CustDataNewfile.xsd");
Response.Write("Data Loaded in Xml File");
}
else
{
Response.Write("No data found in the table");
}
}