How to convert dataset to formatted XML string

Naveenmanam
Posted by Naveenmanam under ASP.NET category on | Views : 5037
convert dataset to formatted XML string



There is a direct function for dataset called GetXml() but it's not returning the formatted output.

Here is how you can achieve it

namespaces to include:
System.IO;



// assuming dsData is dataset you want to convert to formatted xml string

MemoryStream ms = new MemoryStream();
dsData.WriteXml(ms);

StreamReader sr = new StreamReader(ms, System.Text.Encoding.UTF8);
ms.Position = 0;
String strXml = sr.ReadToEnd();
sr.Close();
ms.Close();

Comments or Responses

Login to post response