Hi,
I want to write Dataset to an xml file with schema .
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Apr 8, 2011, 5:31 PM
Purushottam RathorePosted Apr 7, 2011, 2:50 AM
You can try this code for write the dataset into an XML File.
protected void btnExportToXml_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand command = new SqlCommand();
command.CommandText = "SELECT * FROM Employee";
command.CommandType = CommandType.Text;
command.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds, "Employee");
if (ds.Tables[0].Rows.Count > 0)
{
grdXML.DataSource = ds;
grdXML.DataBind();
}
// Get a FileStream object
StreamWriter xmlDoc = new StreamWriter(Server.MapPath("~/FileTest/Testdo.xml"), false);
// Apply the WriteXml method to write an XML document
ds.WriteXml(xmlDoc);
xmlDoc.Close();
}
Thanks