Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to convert datatable to xml in c# dot net.
Posted

This explains how to serialize a DataSet and DataTable into xml.

http://www.diranieh.com/NETSerialization/XMLSerialization.htm[^]

Hope this helps.
 
Share this answer
 
 
Share this answer
 
As your post contains .NET 4.0 tag, this version of .NET provide a method to convert DataTable to the XML.

MSDN Link[^]
 
Share this answer
 
Check this,
String XmlFormatDataSet = datasetObject.GetXml();
 
Share this answer
 
 
Share this answer
 
use datatable's WriteXml() method like this :-

DataTable dt = new DataTable();

System.IO.StringWriter writer = new System.IO.StringWriter();
     dt.WriteXml(writer, XmlWriteMode.WriteSchema, false);
     string result = writer.ToString();
 
Share this answer
 
Comments
CHill60 2-Dec-13 9:45am    
Reason for my downvote - Both solutions 2 and 3 already pointed the querant to the WriteXml method over a year ago

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900