CONVERTING DATASET to XML string

Public Shared Function GetXMLstring(ByVal ds As DataSet) As String
Dim xEle As XElement = New XElement(“Items”)

For Each tb As DataTable In ds.Tables
Dim xEleLevel1 As XElement = New XElement(tb.TableName.Replace(” “, “”))
xEle.Add(xEleLevel1)
For Each row In tb.Rows
Dim xEleLevel2 As XElement = New XElement(“Item”)
xEleLevel1.Add(xEleLevel2)
For Each col As DataColumn In tb.Columns
xEleLevel2.Add(New XElement(col.ColumnName, row(col.ColumnName)))
Next
Next

Next

Return xEle.ToString()
End Function

Advertisements
By Sriramjithendra Posted in C#.NET

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s