title: VB.NET display datagridview with SQL Server database
body: <p>I am new to VB.NET, I would like to connect to a local SQL Server. I just can't connect, hope someone will fix my code.</p>
  
  <pre><code>Public Class Main_Tr
  
      Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
  
      End Sub
  
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  
          Dim connectionString As String = "Data Source=IHOMISSERVER;Initial Catalog=homis;User ID=sa;Initial Catalog=pubs;Integrated Security=True"
          Dim sql As String = "SELECT * FROM table_name"
          Dim connection As New SqlConnection(connectionString)
          Dim dataadapter As New SqlDataAdapter(sql, connection)
          Dim ds As New DataSet()
          connection.Open()
          dataadapter.Fill(ds, "column_name")
          connection.Close()
          DataGridView1.DataSource = ds
          DataGridView1.DataMember = "column_name"
      End Sub
  
      Private Sub Main_Tr_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  
      End Sub
  
  End Class
  </code></pre>