Runoob Tutorial ArchiveEnglish

ADO ADO Recordset

ADO Recordset


To read data from the database, the data must first be loaded into a recordset.


Create an ADO Table Recordset

After creating an ADO database connection, as described in the previous chapter, you can then create an ADO recordset.

Assuming we have a database named "Northwind", we can access the "Customers" table in the database using 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

We can also use SQL to access 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

%>


Extract 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 using 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

%>