ADO Recordset (Record Set)

If you need to read data from the database, the data must first be loaded into a recordset.

Create an ADO Table Recordset (ADO Table Recordset)

After the ADO database connection is created, as described in the previous chapter, the next step is to create an ADO recordset.

Assuming we have a database named "Northwind", we can access the "Customers" table in the database with the following code:

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Customers", conn
%>

Create an ADO SQL Recordset (ADO SQL Recordset)

We can also use SQL to access the data in the "Customers" table:

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn
%>

Extracting data from the recordset

After the recordset is opened, we can extract data from the recordset.

Assuming we use a database named "Northwind", we can access the "Customers" table in the database with the following code:

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn
for each x in rs.fields
   response.write(x.name)
   response.write(" = ")
   response.write(x.value)
next
%>

ADO Recordset Object (ADO Recordset Object)

The ADO Recordset Object can be used to hold a recordset from a database table.

View all methods and properties of the ADO Recordset Object.