V24s

"Get Updates : Subscribe to our e-mail newsletter to receive updates........" "Good Luck frnds" Admission 2018 Application Form 2018 Colleges Entrance Exam 2018 Results 2018 Notification 2018 University Educational Jobs 2018 Government Jobs 2018

Search This Blog v24s guys

Follow by Email

04 April, 2013

C#.Net- How to Convert DataTable to XML String in Asp.net, VB.NET

Introduction:

Here I will explain how to convert datatable to xml string in asp.net using C#, VB.NET.

Description:

In previous posts I explained asp.net, C#, SQL Server Interview Questions, send gridview as email body,upload and download files from gridview and many articles relating to asp.net, C#, VB.NET code snippets. Now I will explain how to convert datatable to xml string in asp.net using C#, VB.NET.

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

C# Code


// By using this method we can convert datatable to xml
public string ConvertDatatableToXML(DataTable dt)
{
MemoryStream str = new MemoryStream();
dt.WriteXml(str, true);
str.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(str);
string xmlstr;
xmlstr = sr.ReadToEnd();
return (xmlstr);
}
VB.NET Code


' By using this method we can convert datatable to xml
Public Function ConvertDatatableToXML(ByVal dt As DataTable) As String
Dim str As New MemoryStream()
dt.WriteXml(str, True)
str.Seek(0, SeekOrigin.Begin)
Dim sr As New StreamReader(str)
Dim xmlstr As String
xmlstr = sr.ReadToEnd()
Return (xmlstr)
End Function
Post a Comment

Popular Posts

Recent Posts

Google Analytics