|
|
Title |
Modifying database records using ADO and VBScripts
|
Summary |
This note shows simple methods to modify records in a database using the ADO interface with VBScript. |
Contributor |
John McTainsh
|
Published |
17-Oct-2000 |
Last updated |
17-Oct-2000 |
|
|
Download demo ASP and MDB files - 12 Kb
Description.
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.
Modifying data in the database. (Editing records)
The important code in this block is where the data is changed in 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.
'Connects to the Access driver and Access database in the Inetpub
'directory where the database is saved
strProvider = "Driver={Microsoft Access Driver (*.mdb)};" &_
"DBQ=D:\Inetpub\Development\ASP\TestADO.mdb;"
'Instantiate a Recordset object and open a recordset using
'the Open method
Set rst = Server.CreateObject("ADODB.recordset")
'Save the new values to the table
sql = "UPDATE Comment" &_
" SET Comment.Author = '" & strNewAuthor & "'" &_
" WHERE Comment.ID = " & nRowID & ";"
rst.open sql,strProvider
What needs further investigation.
We are not doing any error handling. If any one knows how to do this add it to the comments.
|