04 April, 2013

c#- How to Convert Dataset to XML String in Asp.net, VB.NET

Introduction:

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

Description:

In previous posts I explained Convert datatable to xml in asp.net, asp.net, C#, SQL Server Interview Questions, jQuery validate file extension in file upload control, send forgot password as email in asp.netand many articles relating to asp.net, C#, VB.NET code snippets. Now I will explain how to convert dataset to xml string in asp.net using C#, VB.NET.

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

C# Code


DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand("select * from usersInfo", con);
SqlDataAdapter da=new SqlDataAdapter(cmd);
da.Fill(ds);
string str = ds.GetXml();

VB.NET Code


Dim ds As New DataSet()
Dim cmd As New SqlCommand("select * from usersInfo", con)
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds)
Dim str As String = ds.GetXml()

No comments:

Post a Comment