Connecting to Access database using ADOWe 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 StringCreating 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.
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 ObjectTo 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.
As you can see above we have used different arguments and let us try to understand each one with some examples.
This can be the table name or sql query or some other types.
Connection which we have established before
This tells how the recodset will move. By default it is forward only.
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.
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.
This article is written by plus2net.com team.
Be the first to post comment on this article :
|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