
Modifying the Code to Update the Database
You can update the database by calling the Update method of the CustomersTableAdapter. By default, an event handler for the BindingNavigator's Save button is added to the form's code to send updates to the database. This procedure modifies the code to include error handling by wrapping the update call in a try-catch block. You can modify the code to suit the needs of your application.
To add update logic to the application
Double-click the Save button on the BindingNavigator to open the Code Editor to the bindingNavigatorSaveItem_Click event handler.
Replace the code in the event handler to add some error handling. The code should look like the following:
Try
Me.Validate()
Me.CustomersBindingSource.EndEdit()
Me.CustomersTableAdapter.Update(Me.NorthwindDataSet.Customers)
MsgBox("Update successful")
Catch ex As Exception
MsgBox("Update failed")
End Try
try
{
this.Validate();
this.customersBindingSource.EndEdit();
this.customersTableAdapter.Update(this.northwindDataSet.Customers);
MessageBox.Show("Update successful");
}
catch (System.Exception ex)
{
MessageBox.Show("Update failed");
}