Home Search Contact us About us
Title Deleting database records using ADO and VBScripts
Summary This note shows simple methods to delete records from a database using the ADO interface with VBScript.
Contributor John McTainsh
Published 20-Oct-2000
Last updated 20-Oct-2000
Page rating   100% for 1 votes Useless Brilliant

Download demo ASP and MDB files - 12 Kb


The Microsoft¢ÎActiveX¢ÎData Objects (ADO) object model defines a collection of programmable objects that can be used in any language that supports both COM and Automation to access Databases. In this example we will be using ADO to access a Microsoft Access Database.

Note: I have been working on ADO for 5 days now and this is what I have learnt in this time. Also remember you need Microsoft IIS running on the server since this is all server side processing.

How to use it.

Start as always by inserting <%@ LANGUAGE = VBScript %> at the top of the page. The file I will be working with is called TestADO.mdb. When setting these demos up for yourself de sure to change the DBQ=D:\Inetpub\DevelopmentPrivate\TestADO.mdb; path to your local path.

Deleting data in the database. (Removing records)

The important code in this block is where the data is deleted from the database. Click here to view the results. Note an important feature of ASP that is demonstrated in this sample is its ability to post messages to itself. In this way the form and processing logic can be kept in the same page. Note, there is no check to see if the record existed before the delete and no error handling here.
'This is processing of the Form Request
strRowID = request.form("RowID")

strProvider = "Driver={Microsoft Access Driver (*.mdb)};" &_
'Creates an instance of an Active server component
set objConn = server.createobject("ADODB.Connection")
objConn.Open strProvider
'Instantiate Command object and use ActiveConnection property to
'attach connection to Command object
set cm = Server.CreateObject("ADODB.Command")
cm.ActiveConnection = objConn
'Define SQL query
cm.CommandText = "DELETE FROM Comment WHERE ID = " &strRowID

Response.Write( "If the Record existed then it was deleted." )

What needs further investigation.

We are not doing any error handling. If any one knows how to do this add it to the comments.
Comments Date
Home Search Contact us About us