In this demonstration, you'll see how to edit the
values of a record and save the changes to a data
source. First, let's open a recordset and return
all of the students from the StateUBookstore
database. As you can see, we can navigate through all
the current students. Let's change the last name of
the student, Kimberly Bowen to Smith. To save the
changes to the database, click the Update button.
Now, when we disconnect and then reconnect to the
server, you can see that Kimberly's last name
has been changed successfully. Let's take a look at
the code that allows the user to edit data. First,
we need to open a recordset and specify that we
plan to edit the records. The various options for
opening a recordset are discussed in more detail in
Chapter 6. Here, we are binding the text boxes to
the recordset which makes navigation easier. In
addition, when controls are bound to a recordset,
they automatically update the fields of the
recordset during an Edit or an Add New. At this point,
the user can begin making changes to the data. When
the user has finished entering the new values,
they'll need to click the Update button to send the
changes to the server. The code behind the Update
button first verifies that the user wants to save
their changes. The Update method is then called to
make the changes permanent. You can use the
CancelUpdate method to allow the user to abort their
changes. Notice that we do not have to update the
fields of the recordset. Since we've bound the text
boxes to the recordset, this happens automatically.
So, in this demonstration, you saw how to edit an
existing record from a data source.