none
how can i put my dataset into JSON object in Visual Basic WCF? RRS feed

  • Question

  • i am not able to put the dataset into json object , can you please help me in this regards in visual basic.

    thanks in advance

    Tuesday, July 29, 2014 10:39 AM

Answers

All replies

    • Proposed as answer by Mankdng Nef Thursday, August 7, 2014 9:58 AM
    Tuesday, July 29, 2014 3:50 PM
  • Hi,

    The following code will convert the datatable into JSON in VB.NET, please try to check it:

    Public Function ConvertDataTabletoString() As String
    
    Dim dt As New DataTable()
    
    Using con As New SqlConnection("Data Source=SureshDasari;Initial Catalog=master;Integrated Security=true")
    
    Using cmd As New SqlCommand("select title=City,lat=latitude,lng=longitude,description from LocationDetails", con)
    
    con.Open()
    
    Dim da As New SqlDataAdapter(cmd)
    
    da.Fill(dt)
    
    Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
    
    Dim rows As New List(Of Dictionary(Of String, Object))()
    
    Dim row As Dictionary(Of String, Object)
    
    For Each dr As DataRow In dt.Rows
    
    row = New Dictionary(Of String, Object)()
    
    For Each col As DataColumn In dt.Columns
    
    row.Add(col.ColumnName, dr(col))
    
    Next
    
    rows.Add(row)
    
    Next
    
    Return serializer.Serialize(rows)
    
    End Using
    
    End Using
    
    End Function
     
    
    

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Mankdng Nef Thursday, August 7, 2014 9:58 AM
    Wednesday, July 30, 2014 3:03 AM
    Moderator
  • i want to convert not in the data logic class but in the client window how can i do it by clicking on button?

    i have dataset in datagrid view from database i just have to put into json object?

    how it will be done?

    Wednesday, July 30, 2014 1:33 PM
  • i want to convert not in the data logic class but in the client window how can i do it by clicking on button?

    i have dataset in datagrid view from database i just have to put into json object?

    how it will be done?

    What are you talking about? The code is in the link. It's up to you as to how you implement the code, and it doesn't make a difference if it's on the client or service side in dealing with a dataset with a datatable and doing JSON searlization into an object. 

    http://www.codeproject.com/Tips/181230/Convert-DataSet-or-XML-to-JSON-using-VB-NET

    Wednesday, July 30, 2014 2:31 PM