title: SQL queries through VB.NET and JSON
body: <p>I'm completely new to both VB.NET and JSON, and I'm trying to figure out how to do SQL queries towards an SQL 2005 Express server and format the return value to JSON. I got the queries working using this (perhaps very newbie-like) code;</p>
  
  <pre><code>Imports System
  Imports System.Data
  Imports System.Data.SqlClient
  Imports System.Web.UI
  Imports System.Web.UI.WebControls
  
  Partial Public Class SQLConnect
  Inherits System.Web.UI.Page
  'Defines SQL variables
  Dim con As New SqlConnection
  Dim cmd As New SqlCommand
  Dim dr As SqlDataReader
  Dim ReadData As String
  Dim i As Integer
  
  
  Sub Click(ByVal s As Object, ByVal e As EventArgs)
  
      'Define SQL address, database, username and password
      con.ConnectionString = "Data Source=localhost\SQLEXPRESS;Initial Catalog=tempdb;User ID=tesst;Password=test"
      Try
          'Initialize connection
          con.Open()
          'Specify SQL query
          cmd = New SqlCommand("SELECT * FROM Member", con)
          'Execute query, dump result array into variable
          dr = cmd.ExecuteReader()
          messageLabel.Text = "&lt;br /&gt;Connection established&lt;br /&gt;"
  
          While (dr.Read)
              i = 0
              For i = 0 To dr.FieldCount - 1
                  'Dump query results into a variable
                  ReadData += dr.Item(i).ToString
              Next
          End While
  
          'Print query results
          messageLabel2.Text = ReadData
          'Close connection
          con.Close()
      Catch ex As Exception
          messageLabel.Text = "&lt;br /&gt;Connection failed&lt;br /&gt;"
      End Try
  
  
      End Sub
  End Class
  </code></pre>
  
  <p>I have been looking at <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.jsonresult.aspx" rel="nofollow noreferrer">this</a>, and I would love to see some code examples using this class or any other good method.</p>
  
  <p>Any help would be much appreciated, any points and tips you might have.</p>