Page

15.2.2- Connecting to the Database

  by NT Community Manager.
Last Updated  by NT Community Manager.  

PublicCategorized as 15. Writing an Application.

Not tagged.
<< 15.2.1- The Data ModelChapter1515.3.0- Coding the Application >>

Connecting to the Database

When we come to write the code for our application, we'll need to refer to our database. We'll do so via theActiveX Data Objects (ADO) – we'll be using the ADO Connection, Command and Recordset objects to handle the connection to the database,and we'll use the Microsoft Jet Provider for MS Access Databases to privide thedata.

 

In order to specify the data connection, we'll be using the ADO Connection object, like this:

 

  Dim objConn

  Set objConn =Server.CreateObject("ADODB.Connection")

  objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _

               "Data Source=E:\datastores\classified.mdb"

  ...

 

This is a syntax that you've seen earlier in this book – weuse Server.CreateObject to instantiate an ADO Connection object (called objConn),and then Open it, specifying the data providerthat we want to use and the location of the database (I've specified E:\datastores\classified.mdb in this code fragment –your path may differ depending on where you saved your database). You'll seehow this fits into the application later in the chapter.

<< 15.2.1- The Data ModelChapter1515.3.0- Coding the Application >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |