title: Using table adapters to insert a new row doesn't do anything
body: <p>I'm using Visual Studio 2010 to build my application and SQL Server 2005 to store the data. I created a table adapter, dataset and binded the controls to my already made form. The thing is, I'm trying to insert a new record into the database and it won't work!</p>
  
  <p>I can fill the form with a record from the database and update it so I know its definitely connected correctly.  Every time I try to insert a new record, whether it's through a table adapter or manually, I just can't seem to get it to automatically save to the database.</p>
  
  <p>I've put this under the save button</p>
  
  <pre><code>Private Sub SaveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveBtn.Click
  
      Dim CustomerRow As accountingdbDataSet.CustomerRow
      CustomerRow = Me.AccountingdbDataSet._Customer.NewCustomerRow()
      CustomerRow.customerID = CustomerIDBox.Text
      CustomerRow.customerName = FirstNameBox.Text
      CustomerRow.customerSurname = SurnameBox.Text
      CustomerRow.customerAddress1 = AddressBox1.Text
      CustomerRow.customerAddress2 = AddressBox2.Text
      CustomerRow.customerAddress3 = AddressBox3.Text
      CustomerRow.customerPostcode = PostcodeBox.Text
      CustomerRow.customerTelArea = AreaBox.Text
      CustomerRow.customerTelNumber = NumberBox.Text
      CustomerRow.customerEmail = EmailAddressBox.Text
  
      ' Add the row to the Region table
      Me.AccountingdbDataSet._Customer.Rows.Add(CustomerRow)
  
      ' Save the new row to the database
      Me.CustomerTableAdapter.Update(Me.AccountingdbDataSet._Customer)
  
  
  End Sub
  </code></pre>
  
  <p>but that doesn't work. It complains about a NullException even though the fields in my database aren't set to null (apart from the customerID because that's the primary key). I've also tried</p>
  
  <pre><code>Private Sub SaveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveBtn.Click
  
  Try
          Me.Validate()
          Me.CustomerBindingSource.EndEdit()
          Me.CustomerTableAdapter.Update(Me.AccountingdbDataSet)
  
          MessageBox.Show("Updates to the database have been successful.", "Successful Updates", MessageBoxButtons.OK, MessageBoxIcon.Information)
  
      Catch ex As Exception
  
          MessageBox.Show("Updates to the database have failed.", "Unsuccessful Updates", MessageBoxButtons.OK, MessageBoxIcon.Error)
  
      End Try
  
  End Sub
  </code></pre>
  
  <p>which only allows me to update a current record - not insert a new one. I do however have this inserted in the load page</p>
  
  <pre><code>Private Sub NewCustomerPage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  
      Try
  
          Me.CustomerTableAdapter.Fill(Me.AccountingdbDataSet.Customer)
  
      Catch ex As Exception
          MessageBox.Show("The database file is unavailable", "Database Unavailable", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
          Me.Close()
  
      End Try
  
  
  End Sub
  </code></pre>
  
  <p>Where am I going wrong?</p>