drupal stats

Export DataGridView to XML using C#

July 7th, 2011 DataGridView 0 Comments


Get DataTable from DataGridView

DataTable dt = new DataTable();

dt = (DataTable)dataGridView1.DataSource;

 

DataSet support the transition to XML, so we will move DataTable above to a DataSet

DataSet ds = new DataSet();

ds.Tables.Add(dt);

 

Export DataSet to XML

ds.WriteXml("D:\\Customers.xml", System.Data.XmlWriteMode.IgnoreSchema);

 

Complete Source Code

private void Form1_Load(object sender, EventArgs e)

{

    DataTable dt = _customers.GetCustomers();

    dataGridView1.DataSource = dt;

}

 

private void btnExportXML_Click(object sender, EventArgs e)

{

    DataTable dt = new DataTable();

    dt = (DataTable)dataGridView1.DataSource;

    DataSet ds = new DataSet();

    ds.Tables.Add(dt);

    ds.WriteXml("D:\\Customers.xml", System.Data.XmlWriteMode.IgnoreSchema);

}

Export DataGridView to XML thumb Export DataGridView to XML using C#

XML File thumb Export DataGridView to XML using C#

Tags: datagridview to xml, export datagridview to xml, datagridview to xml c#, c# datagridview to xml, datagridview xml, save datagridview to xml, export to xml c#, c# save datagridview to xml, datagridview c# xml, c# datagridview export to xml

Related posts:

  1. Export GridView to Excel in ASP.NET
  2. Export DataTable to CSV/Excel
  3. Export GridView to CSV
  4. Save Images to SQL Server

No Comments