Page 312 - DCAP408_WEB_PROGRAMMING
P. 312
Web Programming
Notes 14.3.2 ASP Database Updating Existing Records
If your database application did not have the ability to update or modify existing database
entries, then it would be severely limiting in its potential. For example, imagine having a
customer database in which you did not have the ability to change the contact information for a
customer. You would not be able to update the customer’s mailing address, phone number, or
email address. How about an inventory management system that had an inability to update the
price or quantity of an item in stock?
For today’s mainstream database applications, database maintenance is a necessity. To that end,
there are two main methods of updating information utilizing ADO.
Update command is not only used to add a new record but also used to make changes to the
existing records. Instead of calling AddNew move to the record you want to change. Set the field
value with the assignment operator as done in the earlier programs. When the values are
assigned Update method should be called.
objRS.(“username”) = “Anshul”
objRS(“email”) = sdf@asd.com
objRS.Update
the first two lines change the values of the username and email fields of the current record. Then,
calling Update save those changes to the database.
Some times you need to Cancel the Update done in the previous records. The following program
will tell how the cancellation command will work
objRS(“username”) = “nikhil”
objRS(“email”) = “sdf@asd.com
objRS.CancelUpdate
CancelUpdate here undo the preceding lines. Mostly the CancelUpdate command is used with
IF…. The program basically becomes
objRS(“password”) = Request(“Pass”)
objRS(“email”) = Request(“Email”)
If objRS (“password”) = “” then
objRS.CancelUpdate
else
objRS.Update
End if
This will cancel the changes made to the record if the password is an empty string. Otherwise,
the changes are saved using Update.
ASP Database The Update Method in More Detail
Similar to the addnew method, there are two optional parameters that can be used. These are the
fieldlist and the valuelist parameters. These parameters work in the same manner as the ones
used by the addnew method.
The fieldlist parameter can be a single field name, or an array of field names, or the numeric
(ordinal) position of the fields in the new record. For both the single name and array of names,
each name must be enclosed within a pair of double quotes.
306 LOVELY PROFESSIONAL UNIVERSITY