Home Search Contact us About us
Title Reading database with ADO and VBScripts
Summary This note shows simple methods to add records to a database using the ADO interface with VBScript.
Contributor John McTainsh
Published 18-Oct-2000
Last updated 18-Oct-2000
Page rating   70% for 2 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.

Read data from the database. (View recordes)

The important code in this block is where the record is read from the database. Click here to view the results.
'Create and open connection to the data source
strProvider = "Driver={Microsoft Access Driver (*.mdb)};" &_

'Setup the match query
strQuery = "SELECT * FROM Comment;"
'Instantiate a Recordset object and open a recordset using the Open method 
Set rst = Server.CreateObject("ADODB.recordset")
rst.Open strQuery, strProvider

While ( not rst.EOF )
    strAuthor          = rst( "Author" )
    nAge               = rst( "Age" )
    strMessage         = rst( "Message" )
    dateLastRefreshed  = rst( "LastRefreshed" )
    nDay    = Day( dateLastRefreshed )
    nMonth  = Month( dateLastRefreshed )
    nYear   = Year( dateLastRefreshed )

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
Read hangs some times. 30-Oct-2000 Harold Edwards
Sometimes the read hangs if it does not get a hit in the database. Has anyone else had this problem?
here 14-Oct-2004 brian
Home Search Contact us About us