|
To be able to read database data, the data must first be
loaded into a recordset.
Create an ADO Table Recordset
After an ADO Database Connection has been created, as
demonstrated in the previous chapter, it is possible to create
an ADO Recordset.
Suppose we have a database named "Northwind", we can get
access to the "Customers" table inside the database with the
following lines:
<% 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 get access to the data in the "Customers" table
using SQL:
<% 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 a recordset is opened, we can extract data from
recordset.
Suppose we have a database named "Northwind", we can get
access to the "Customers" table inside the database with the
following lines:
<% 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 %>
The ADO Recordset Object
The Recordset Object is used to hold a set of records from a
database table.
Syntax
rs.method rs.property
The most common Methods and Properties
Methods
Method Description
AddNew Creates a new record
Close Closes a Recordset
Delete Deletes the current record or group of records
MoveFirst Moves to the first record
MoveLast Moves to the last record
MoveNext Moves to the next record
MovePrevious Moves to the previous record
Open Opens a Recordset
Update Saves any changes
Properties
Property Description
BOF Returns true if the current record is before the first
record, otherwise it returns false
EOF Returns true if the current record is after the last
record, otherwise it returns false
Fields Contains all of the field objects for the Recordset
Object
RecordCount Returns how many records there are in a Recordset
object
Sort Specifies a comma-separated list of field names the
Recordset is sorted on
For a complete reference of the Recordset Object's methods,
properties and events,
|