|
Using MS Access Databases
Part:
1
2
3
4
5
(Continued from previous part...)
Here is what I did to test those steps:
I ran MS Access. Created a blank database file called: "hello.mdb". Then created a table called "message"
in the database. In the "message" table, I added one field called "text".
Before closing the database file, I inserted one row in the "message" table with "Hello world!".
Then I copied "hello.mdb" to my local IIS server as "c:\inetpub\wwwroot\cgi-bin\hello.mdb".
My ASP script for this test was very simple, hello_access.asp:
<script language="vbscript" runat="server">
' hello_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("SELECT * FROM message")
Response.write(oRes("text"))
oRes.close
oConn.close
</script>
This script was also copied to my local IIS server as "c:\inetpub\wwwroot\hello_access.asp".
Then I opened Internet Explorer with http://localhost/hello_access.asp. I got:
Hello world!
Working, right?
Notes on this test:
- The database driver "Microsoft.Jet.OLEDB.4.0" is smart to know how to talk to a MS Access database.
- Server.MapPath() is used to convert a Web server path name to a Windows harddisk path name.
- I did not use any loop structure on the result object. Only the first row is retrieved from
the result object.
Persisting Data to MS Access Databases
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.
(Continued on next part...)
Part:
1
2
3
4
5
|