V24s

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

Search This Blog v24s guys

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

No comments:

Popular Posts

Recent Posts

Google Analytics