Persisting Data to MS Access Databases

This section provides a tutorial example on how to persist data to MS Access database using the Execute() method to run an INSERT statement.

Persisting data to a MS Access database is also easy:

1. Create a MS Access database file with a table inside.

2. Move the MS Access file to a your Web server.

3. Create an ADODB.Connection object in your ASP page. And link the object to the MS Access file with the Open() method.

4. Prepare a SQL insert statement. And execute the insert statement through the connection object.

5. Close the connection object.

Here is what I did to test those steps:

I used the same MS Access database as my previous test. The database file is located in same place: "c:\inetpub\wwwroot\hello_access.asp".

My ASP script for this test was very simple, insert_access.asp:

<script language="vbscript" runat="server">
'  insert_access.asp
'  Copyright (c) 2005 by Dr. Herong Yang, http://www.herongyang.com/

   Set oConn = Server.CreateObject("ADODB.Connection")
   oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
      Server.MapPath("/cgi-bin/hello.mdb")
   
   Set oRes = oConn.Execute("INSERT INTO message VALUES ('I am here.')")

   Set oRes = oConn.Execute("SELECT * FROM message")
   Do While NOT oRes.EOF
      Response.write(oRes("text") & "<br>")
      oRes.MoveNext
   Loop

   oRes.close
   oConn.close 
</script>

Table of Contents

 About This Book

 ASP (Active Server Pages) Introduction

 IIS (Internet Information Services) 5.0

 MS Script Debugger

 VBScript Language

 ASP Built-in Run-time Objects

 ASP Session

 Creating and Managing Cookies

 Managing Sessions with and without Cookies

 scrrun.dll - Scripting Runtime DLL

 Managing Response Header Lines

 Calculation Speed and Response Time

 ADO (ActiveX Data Object) DLL

Working with MS Access Database

 Connecting ASP Pages to MS Access Databases

 "hello_access.asp" - MS Access Example

Persisting Data to MS Access Databases

 Running "insert_access.asp"

 Protecting Data in SQL Statements

 Protecting Data in SQL Statements - Test Script

 Guest Book Application Example

 References

 Full Version in PDF/EPUB