Start by creating another form, just like you did in Part 1. Your form should have the same labels, textboxes, and buttons. Add three more buttons: btnAdd, btnUpdate, and btnDelete. Don't forget to go into Project properties and set this new form (Form2) as the startup object.

The code for Form Load, btnFirst, btnPrevious, btnNext, and btnLast is almost the same as in the form presented in Part 1, but with a few small differences. Instead of filling the textboxes individually each time, you'll call a single method, FillFields(), which looks at the intCurrentIndex variable and fills up the textboxes.

'We move back only if we're not at the first row.
If intCurrentIndex > 0 Then
'Subtract one from the current index.
intCurrentIndex = intCurrentIndex - 1
FillFields()
Else
MessageBox.Show("You're already at the first record.")
End If

Also, move the declaration of the connection object and the dataadapter object to class level variables.

Dim ds As New DataSet()
Dim intCurrentIndex As Integer = 0
Dim da As New OleDbDataAdapter()
Dim conn As New OleDbConnection()

You should then specify the dataadapter's select statement in the form's load event like so:

Getting to the guts and purpose of this form now, you have to add a record, update a record, and delete a record. ADO.NET provides many objects (and therefore ways) to accomplish this. You can use stored procedures with the OledbCommand object, or you can use SQL statements directly with the OleDbCommand object, or even use the Data Adapter to perform the updates.

There are different reasons for using each method, but for the purpose of this tutorial, the Data Adapter will continue to be used.

Start with the update method. Because the dataadapter filled the dataset, you can get the dataadapter to perform the update too. All you need to do is tell it what to do when the time comes to update.

If you don't understand this, don't let it daunt you. Go over it slowly and you'll see: @FirstName, @LastName, @Location, and @EmployeeID are parameters in your UPDATE statement. The Parameters that will be added in the subsequent lines take arguments that are the parameter name (@FirstName), the data type(OleDbType.VarChar), the size of the field (40), and the name of the column in the dataset that will contain the new value ("FirstName").

In the btnUpdate's click event, you now can ask the dataadapter to perform an udpate.

If you are working with SQL Server instead of Access, the principles remain the same; just the namespace changes from System.Data.Oledb to System.Data.SqlClient. You will have SqlDataAdapter instead of OleDbDataAdapter, and so on.