Import Data from datatable

Category: c# language

Question

D Gopinath on Thu, 18 Oct 2012 07:24:58


I have to import data from datatable to Xml and then export into excel?

Replies

Hirendra Sisodiya on Thu, 18 Oct 2012 08:01:14


you can use the WriteXML() method for doing this, as shown here:

DataTable dt = new DataTable("tblStudent");
            dt.Columns.Add("Name");
            dt.Columns.Add("Id");

            dt.Rows.Add();
            dt.Rows[0]["Name"] = "John";
            dt.Rows[0]["Id"] = "1";

            dt.Rows.Add();
            dt.Rows[1]["Name"] = "Ram";
            dt.Rows[1]["Id"] = "2";

            dt.WriteXml("C:\\test.xml");

You can down load the full code sample to export data table to excel format from here:

http://code.msdn.microsoft.com/vstudio/Export-DataTable-object-to-b3e2c1f0

Thanks