Converting a Data Table to JSON String...............

Posted by Godly77 under ASP.NET category on | Points: 40 | Views : 3847
Data Table to JSON String

Below function helps you to convert Datatable to JSON String

    Public Function ConvertDataTableToJSON(JDataTable As DataTable) As String
Dim JResString As String = ""
Dim List_Rows As New List(Of Dictionary(Of String, Object))
Dim Dic_Row As Dictionary(Of String, Object)
For Each JDTAB_Row As DataRow In JDataTable.Rows
Dic_Row = New Dictionary(Of String, Object)
Dic_Row.Add(JDTAB_Row(0), JDTAB_Row(1))
Dim JSerialiser As New DataContractJsonSerializer(List_Rows.[GetType]())
Dim _MemoryStram As New MemoryStream()
JSerialiser.WriteObject(_MemoryStram, List_Rows)
JResString = Encoding.[Default].GetString(_MemoryStram.ToArray())
Return JResString
End Function

Comments or Responses

Login to post response