If you want to read data from a database, the data in it must first be loaded into a recordset. After the ADO database connection is created, as described in the previous chapter, you can then create an ADO recordset. Suppose we have a database named “Northwind”, and we can access the “Customers” table in the database with the following code: We can also use SQL to access data in the “Customers” table: After the recordset is opened, we can extract data from the recordset. Suppose we use a database named “Northwind”, and we can access the “Customers” table in the database with the following code:Create an ADO Table Recordset ¶
<%
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) ¶
<%
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 a recordset ¶
<%
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
%>