title: How to update an Access DB from a DataGridView in Visual Basic
body: <p>I am creating an inventory application which runs off of an Access DB in visual studio, using visual basic. I can populate my data grid view just fine, but when I try to add new information into the data grid view, it does not number correctly and it does not append my database. </p>
  
  <p>I have tried binding and updating using the table adapter.</p>
  
  <pre><code>Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  
      CustomersBindingSource.AddNew()
  
      Me.Validate()
      Me.CustomersTableAdapter.Update(Me.Database1DataSet.Customers)
      Me.CustomersBindingSource.EndEdit()
  End Sub
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>Public Class Form1
      Private Sub enterbtn_Click(sender As Object, e As EventArgs) Handles enterbtn.Click
          If username.Text = "Tanner" And password.Text = "bmis365" Then
              GroupBox1.Visible = False
          Else
              MsgBox("Incorrect Username or Password, please try again.")
              username.Clear()
              password.Clear()
              username.Focus()
          End If
      End Sub
  
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  
      DataGridView1.CurrentCell = Nothing
  
      'This line of code loads data into the 'Database1DataSet.Customers' table. You can move, or remove it, as needed.
  
      Me.CustomersTableAdapter.Fill(Me.Database1DataSet.Customers)
  
  End Sub
  
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  
      'This is where my new info is to be appended into the database, once the button is clicked. 
  
      CustomersBindingSource.AddNew()
  
      Me.Validate()
      Me.CustomersTableAdapter.Update(Me.Database1DataSet.Customers)
      Me.CustomersBindingSource.EndEdit()
  End Sub
  
  
  Private Sub searchbtn_Click(sender As Object, e As EventArgs) Handles searchbtn.Click
  
      'The Following Code is from https://social.msdn.microsoft.com/Forums/vstudio/en-US/36c54726-4f49-4e15-9597-7b201ec13ae7/search-in-datagrid-using-textbox-vbnet-without-data-connectivity?forum=vbgeneral
  
      For Each row As DataGridViewRow In DataGridView2.Rows
          For Each cell As DataGridViewCell In row.Cells
              If Not IsNothing(cell.Value) Then
                  If cell.Value.ToString.StartsWith(searchbar.Text, StringComparison.InvariantCultureIgnoreCase) Then
                      cell.Selected = True
                      DataGridView2.CurrentCell = DataGridView2.SelectedCells(0)
  
                  End If
              End If
          Next
      Next
  End Sub
  End Class
  </code></pre>
  
  <p>My output initially has 3 rows(numbered 1, 2, and 3) but any that are added through the application have the numbers -1, -2, -3 and so on. Also, when I close the program and restart it, my original rows (1, 2, and 3) are still there from when I entered them in the DB file, but any that were added through my application are gone.</p>