title: VB.net data binding
body: <p>Hey this is an homework assignment and I just cannot figure it out. Any help would be great!</p>
  
  <p>Create a SQL Server database named "people" that has the following table. Please use Visual Studio 2012 and create a local service based database</p>
  
  <p>people_id  int PK identity
  firstname varchar(30)
  lastname varchar(40)</p>
  
  <p>Create a Windows forms program that lists the id, firstname and lastname in a datagridview</p>
  
  <p>Provide functionality (in code using command object and parameters, no wizards) to add, update  and delete from the database table and reflect the changes in the datagridview.</p>
  
  <p>This is the code I already have. I can run my program and the data will show up in the datagridview, but whenever I go to add update or delete data nothing happens. I am not throwing errors or anything. I have no idea how to fix this, please help!!</p>
  
  <pre><code>Imports System.Data
  Imports System.Data.SqlClient
  
  Public Class Form1
  
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
      Me.PeopleTableAdapter.Fill(Me.PeopleDataSet.people)
  End Sub
  
  Private Function getConnString() As String
      Return My.Settings.PeopleConnectionString.ToString()
  End Function
  
  Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
      Me.Close()
  End Sub
  
  Private Function getConnection() As String
      Return My.Settings.PeopleConnectionString.ToString()
  End Function
  
  Private Function getPeople(lName As String) As DataTable
      Dim sql As String
      Dim conn As SqlConnection
      Dim cmd As SqlCommand
      Dim da As SqlDataAdapter
      Dim dt As New DataTable
      Dim plName As New SqlParameter
      plName.ParameterName = "@lName"
      plName.Value = lName
      sql = "select * from people where lName = @lName"
      conn = New SqlConnection(getConnection())
      conn.Open()
      cmd = New SqlCommand(sql, conn)
      cmd.Parameters.Add(plName)
      da = New SqlDataAdapter(cmd)
      da.Fill(dt)
      conn.Close()
      Return dt
  End Function
  
  Private Sub AddPerson(fname As String, lname As String, person_ID As Integer)
      Dim sql As String
      Dim conn As SqlConnection
      Dim cmd As SqlCommand
      sql = "insert into people(fName, lName, person_ID) values("
      sql += "@fName, @lName, @person_ID)"
      conn = New SqlConnection(getConnection())
      conn.Open()
      cmd = New SqlCommand(sql, conn)
      cmd.Parameters.AddWithValue("@fName", fname)
      cmd.Parameters.AddWithValue("@lName", lname)
      cmd.Parameters.AddWithValue("@person_ID", person_ID)
      cmd.ExecuteNonQuery()
      conn.Close()
  End Sub
  
  Private Sub btnADD_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
      Try
          AddPerson(txtfName.Text, txtlName.Text, txtpID.Text)
          MessageBox.Show("Added")
      Catch ex As Exception
          MessageBox.Show("Error" &amp; ex.Message)
      End Try
  End Sub
  
  Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
      If DataGridView1.SelectedRows.Count &gt; 0 Then
          Dim dr As DataGridViewRow = DataGridView1.SelectedRows(0)
          txtfName.Text = dr.Cells(1).Value.ToString()
          txtlName.Text = dr.Cells(2).Value.ToString()
          txtpID.Text = dr.Cells(0).Value.ToString()
      End If
  End Sub
  
  Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
      Dim sql As String
      Dim conn As SqlConnection
      Dim cmd As SqlCommand
      sql = "update people set fName=@fName, lName=@lName"
      sql += " where person_ID=@person_ID"
      conn = New SqlConnection(getConnection())
      conn.Open()
      cmd = New SqlCommand(sql, conn)
      cmd.Parameters.AddWithValue("@fName", txtfName.Text)
      cmd.Parameters.AddWithValue("@lName", txtlName.Text)
      cmd.Parameters.AddWithValue("@person_ID", txtpID.Text)
      cmd.ExecuteNonQuery()
      conn.Close()
  End Sub
  
  Private Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click
      Dim sql As String
      Dim conn As SqlConnection
      Dim cmd As SqlCommand
      sql = "delete from people where person_ID=@person_ID"
      conn = New SqlConnection(getConnection())
      conn.Open()
      cmd = New SqlCommand(sql, conn)
      cmd.Parameters.AddWithValue("@person_ID", txtpID.Text)
      cmd.ExecuteNonQuery()
      conn.Close()
  
  End Sub
  End Class
  </code></pre>