Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
There will undoubtedly be times when you want to delete a record or set of records from a database. For example, you might decommission the DNS Server service on a computer; in turn, you will then need to delete that computer from the database table that contains the names of your DNS servers. Or suppose you maintain three months of performance monitoring information in a database. Each month you will need to delete some of the old data to make room for the new data. For example, in April you will need to delete the data for January. After you add the April data, the database will again contain data for three months: February, March, and April.
To delete a record by using ADO, do the following:
When you use the Delete method to delete a record, the record will be deleted as soon as the method is called. You do not need to use the Update method to apply the changes. No warning of any kind will be issued before the record is deleted.
Listing 17.19 contains a script that deletes a record from a database. To carry out this task, the script must perform the following steps:
These constants will be used to configure the CursorLocation, CursorType, and LockType for the connection.
The Connection object makes it possible for you to issue queries and other database commands.
The Recordset object stores the data returned from your query.
Be sure to append a semicolon (;) to the DSN name.
The Open method requires four parameters:
The variable strSearchCriteria will serve as the search criteria for the Find method.
Listing 17.19 Deleting Selected Records from a Database
|
|
Send us your feedback | « Previous | Next » |