Modifying Data  «Prev  Next»

Lesson 4Deleting Records
Objective Use the recordset object to delete records.

Deleting Database Records

The VirtualBookShelf application will need the capability to remove records from the database. Some books will no longer be carried in inventory and customers will be deleted after some period of inactivity. You will want to remove these from the database to get rid of unnecessary data and to reduce storage space.
Just as you have seen in the lessons for updating and inserting records, Visual Studio makes it very easy to add delete capability. The following simulation takes you through the steps for adding a Delete button to CustManage.asp:

Deleting Records using the recordset Object

  1. We begin with CustManage_1.asp open in the source editor. The first step is to add a Button DTC to the page. For the purpose of this simulation, you only need to click the Button in the list on the left side of the screen and we'll drag the button into the page for you.
  2. The button is now in the page just below the Insert button. Now it is time set the button's properties. You do this by right-clicking the button.
  3. The menu is displayed, select properties.
  4. The Button Properties dialog is now displayed. There are only two properties that need to be set: Name to give the button a unique identifier, and Caption to set the text to be displayed on the button. Enter DeleteBtn for the name, and Delete for the caption. Then click OK.
  5. Now it's time to add the desired functionality to the button. To do so, you need to open the Script Outline window. This is done from the View item on the drop-down menu.
  6. On the View menu, move the mouse pointer over Other Windows. However, for the purpose of this simulation, you will need to click Other Windows.
  7. The Script Outline is now open. Now add code to the Delete button's onclick event handler just like you did in the previous two lessons. Begin by expanding the Delete button contents do gain access to its onclick event.
  8. Now double-click on the Delete button's onclick event.
  9. Now add the code in the DeleteBtn_onclick code block. Enter CustRecords.deleteRecord on the line between Sub DeleteBtn_onclick() and End Sub. Then right-click the source editor to view the page in the browser.
  10. Now select View in Browser.
  11. A record is displayed in the page. Test the Delete button by clicking it.
  12. The record was deleted and the next record is now displayed in the page. This is the end of the simulation.

In the next lesson, you will learn to coerce scripting data types to match database types.