ASP ADO
This lesson will provide a
brief overview of what ADO is and
why it is necessary to have in
your ASP programming repertoire.
ADO stands for ActiveX Data
Objects. ActiveX Data Objects are
a collection of components that
can be used in your ASP programs.
Accessing the Database
ADO is specifically used as
means to communicate and
manipulate a database. The types
of databases ADO will allow your
ASP program to interact include
Access, MySQL, and MSSQL to name a
few. In this lesson we will be
connecting to an Access database,
so you will need to have access to
Access(hehe) to complete this
lesson.
Create Your Access Database
Before you can connect to the
Access database you have to first
create the Access database file.
Fire up your copy of MS Access and
create the following database:
- Create a New blank database
called "codeteller.mdb" (without
the quotes) and save it to "C:\Inetpub\wwwroot\codetellerASP\"
(without the quotes)
- Use the wizard to create the
database.
- Add two fields to your
table: FirstName and LastName
- Click Next
- Name the table "codetellerTable"
(without the quotes)
- Select "Yes, set a primary
key for me"
- Click Next
- Click Finish
Now that we have our database
all that remains to connect to it.
Using ADO to Connect to an
Access Database
Create an ASP file called "codetellerADO.asp"
and save it in the same directory
as your Access database file.
In the following ASP code we
first create an ADO database
connection and then we set up the
ConnectionString and finally we
call the Open method with our
Access database filename to finish
the opening process.
ASP Code:
<%
Dim myConn
Set myConn =
Server.CreateObject("ADODB.Connection")
myConn.Open =
("DRIVER={Microsoft Access" &_
" Driver (*.mdb)};DBQ=" &_
"C:\Inetpub\wwwroot\codetellerASP\codeteller.mdb;")
myConn.Close()
Set myConn = nothing
%> |
|
|
|
|