SQL PHP HTML ASP JavaScript articles and free scripts to download

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.
Google+

Further readings
Changing second list values based on selection of first list
Connecting string and recordset object for data handling of Access db
Recordset object properties like EOF, BOF, MoveNext etc in ASP to browse through the records
Displaying all the records of an access table by looping through the records
Dynamically listing drop down list options with formatted access table data
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer