Vinit Patel

Posts Tagged ‘XML To DataTable

// <summary>
/// method for reading an XML file into a DataTable
/// </summary>
/// <param name=”file”>name (and path) of the XML file</param>
/// <returns></returns>
public DataTable ReadXML(string file)
{
//create the DataTable that will hold the data
DataTable table = new DataTable(“XmlData”);
try
{
//open the file using a Stream
using(Stream stream = new  FileStream(file, FileMode.Open, FileAccess.Read))
{
//create the table with the appropriate column names
table.Columns.Add(“Name”, typeof(string));
table.Columns.Add(“Power”, typeof(int));
table.Columns.Add(“Location”, typeof(string));

//use ReadXml to read the XML stream
table.ReadXml(stream);

//return the results
return table;
}
}
catch (Exception ex)
{
return table;
}
}

The other useful link is,

http://www.codeproject.com/Messages/3094681/XML-to-DataTable.aspx


Calendar

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Stats Of Blog

  • 7,719 hits

Cluster Map