Connecting to Access database using ADO

We will be using ActiveX Data Objects (ADO) to create a connection to Access database. ADO model contains six objects and we will be using Connection String to connect to database.

Connecting String

Creating a Connection String using ADO and opening the connection To connect to Access database we can create a connection object by using ADO. Here is an example of connection object creation and opening the connection object.
Set objconn = Server.CreateObject("ADODB.Connection")
objconn.ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/months.mdb")
objconn.Open
Note that here we have using server MapPath to locate the access database. Here database is stored inside db directory relative to the script running this code. Now we have opened the connection to the access database next is we need one object to handle records.

Recordset Object

To handle records of a MS access table we need recordset object provided by ADO. Using this object we can get a subset of records of our table. We can declare Record set object like this.
Set objRs = Server.CreateObject("ADODB.Recordset")
By just declaring the recordset object we can't handle data, we need to open it and during the opening process we can give different arguments to handle the recordset object. Here is the syntax of opening a Recordset object.
Recordset.Open Source, Connection, cursortype, locktype, commandtype 
As you can see above we have used different arguments and let us try to understand each one with some examples.

Source
This can be the table name or sql query or some other types.

Connection
Connection which we have established before

Cursourtype
This tells how the recodset will move. By default it is forward only.

Locktype
This tell how we handle the record. As there will be more than one client trying to access / update the data. By default it is read only.

Commandtype
Tells how the source parameter to be evaluated. adCmdTable tells that the source is a table. Let us try to display all month names stored in an access table.
Display records Dropdown 2nd Dropdown Properties
ASP Home

plus2net.com


Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer