Runoob Tutorial ArchiveEnglish

ADO Recordset Object

ADO Recordset Object


Instance

GetRows
This example demonstrates how to use the GetRows method.


Recordset Object

The ADO Recordset Object is used to hold a recordset from a database table. A Recordset Object consists of records and columns (fields).

In ADO, this object is the most important and most frequently used object for operating on database data.

ProgID

set objRecordset=Server.CreateObject("ADODB.recordset")

When you first open a Recordset, the current record pointer points to the first record, and the BOF and EOF properties are False. If there are no records, the BOF and EOF properties are True.

The Recordset object supports two types of updates:

In ADO, 4 different cursor (pointer) types are defined:

The cursor type can be set via the CursorType property or the CursorType parameter in the Open method.

Note: Not all providers support all methods and properties of the Recordset object.


Properties

Properties Description
AbsolutePage Sets or returns the page number value in the Recordset object.
AbsolutePosition Sets or returns a value that specifies the sequential position (record number) of the current record in the Recordset object.
ActiveCommand Returns the Command object associated with the Recordset object.
ActiveConnection Sets or returns the connection definition if the connection is closed, or sets or returns the current Connection object if the connection is open.
BOF Returns true if the current record position is before the first record, otherwise returns false.
Bookmark Set or return a bookmark. This bookmark saves the current position of the record.
CacheSize Set or return the number of records that can be cached.
CursorLocation Set or return the position of the cursor service.
CursorType Set or return the cursor type of a Recordset object.
DataMember Sets or returns the name of the data member to retrieve from the object referenced by the DataSource property.
DataSource Specifies an object that contains the data to be represented as a Recordset object.
EditMode Returns the edit status of the current record.
EOF Returns true if the current record position is after the last record, otherwise returns false.
Filter Returns a filter for the data in the Recordset object.
Index Sets or returns the name of the current index of the Recordset object.
LockType Sets or returns the value specifying the lock type when editing a record in the Recordset.
MarshalOptions Sets or returns a value that specifies which records are returned to the server.
MaxRecords Sets or returns the maximum number of records returned by a query.
PageCount Returns the number of data pages in a Recordset object.
PageSize Sets or returns the maximum number of records allowed on a single page of a Recordset object.
RecordCount Returns the number of records in a Recordset object.
Sort Sets or returns one or more field names to sort the Recordset by.
Source Sets a string value, a reference to a Command object, or returns a string value that indicates the data source of the Recordset object.
State Returns a value that describes whether the Recordset object is open, closed, connected, executing, or retrieving data.
Status Returns the current state of a batch update or other bulk operation.
StayInSync Sets or returns whether the reference to the child record changes when the position of the parent record changes.

Method

Method Description
AddNew Creates a new record.
Cancel Roll back one execution.
CancelBatch Roll back one batch update.
CancelUpdate Roll back changes made to a record in a Recordset object.
Clone Create a copy of an existing Recordset.
Close Close a Recordset.
CompareBookmarks Compare two bookmarks.
Delete Delete a record or a set of records.
Find Search for a record in a Recordset that meets a specified condition.
GetRows Copy multiple records from a Recordset object to a two-dimensional array.
GetString Return the Recordset as a string.
Move Move the record pointer in the Recordset object.
MoveFirst Move the record pointer to the first record.
MoveLast Move the record pointer to the last record.
MoveNext Move the record pointer to the next record.
MovePrevious Move the record pointer to the previous record.
NextRecordset Clears the current Recordset object by executing a series of commands and returns the next Recordset.
Open Open a database element, which provides access to records of a table, query results, or saved Recordset.
Requery Update the data in the Recordset object by re-executing the query the object is based on.
Resync Refresh the data in the current Recordset from the original database.
Save Save the Recordset object to a file or Stream object.
Seek Search the index of a Recordset to quickly locate rows matching a specified value and set it as the current row.
Supports Returns a boolean value that defines whether the Recordset object supports a specific type of functionality.
Update Saves all changes made to a single record in the Recordset object.
UpdateBatch Saves all changes in the Recordset to the database. Use in batch update mode.

Event

Note: You cannot use VBScript or JScript for processing (only Visual Basic, Visual C++, and Visual J++ are allowed to process events).

Events Description
EndOfRecordset Triggered when attempting to move to a row beyond the end of the Recordset.
FetchComplete Triggered after all records in an asynchronous operation have been read.
FetchProgress Triggered periodically during asynchronous operations to report how many records have been read.
FieldChangeComplete Triggered when the value of a Field object changes.
MoveComplete Triggered after the current position in the Recordset changes.
RecordChangeComplete Triggered after a record changes.
RecordsetChangeComplete Triggered after a change to the Recordset.
WillChangeField Triggered before the value of a Field object changes
WillChangeRecord Triggered before a record changes.
WillChangeRecordset Triggered before a change to the Recordset.
WillMove Triggered before the current position in the Recordset is changed.

Collection

Collection Description
Fields Indicates the number of Field objects in this Recordset object.
Properties Contains all Property objects in the Recordset object.

Properties of the Fields collection

Property Description
Count

Returns the number of items in the fields collection, starting from 0.

Example:

countfields = rs.Fields.Count
Item(named_item/number)

Returns a specific item from the fields collection.

Example:

itemfields = rs.Fields.Item(1)

Or itemfields = rs.Fields.Item("Name") |

Properties collection properties

Property Description
Count

Returns the number of items in the properties collection. Starts at 0.

Example:

countprop = rs.Properties.Count
Item(named_item/number)

Returns a specific item from the properties collection.

Example:

itemprop = rs.Properties.Item(1) or itemprop = rs.Properties.Item("Name") |