Bookmark and Share

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.

Advertise on Tizag.com

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:

  1. Create a New blank database called "tizag.mdb" (without the quotes) and save it to "C:\Inetpub\wwwroot\tizagASP\" (without the quotes)
  2. Use the wizard to create the database.
  3. Add two fields to your table: FirstName and LastName
  4. Click Next
  5. Name the table "TizagTable" (without the quotes)
  6. Select "Yes, set a primary key for me"
  7. Click Next
  8. 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 "tizagADO.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\tizagASP\tizag.mdb;")
myConn.Close()
Set myConn = nothing
%>
Bookmark and Share




Found Something Wrong in this Lesson?

Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!

Advertise Here

More Tutorials!
Microsoft Office Tutorials Artist Tutorials