How to Convert DataTable to XML String in Asp.net c#

How to Convert DataTable to XML String in Asp.net c#

you want to convert datable to xml you need to write a code as shown below

public string ConvertDatatableToXML(DataTable dt)
{
MemoryStream str = new MemoryStream();
dt.WriteXml(str, true);
str.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(str);
string xmlstring="";
xmlstring = sr.ReadToEnd();
return (xmlstring);
}

2020-02-16