ADO GetRows Method

Home | About me | EXCEL VB Programming (XL97-2003) | ACCESS Programming | EXCEL VB.Net Programming | EXCEL Spreadsheet Functions Material Management  |  Guestbook
 

ADO GetRows Method

The GetRows method is used to copy records from a Recordset object into a variant that is a two-dimensional array. The variant array is automatically dimensioned (sized) to fit the requested number of columns and rows. To allow backwards compatibility with earlier versions of ADO, the columns are placed in the first dimension of the array and the rows are placed in the second dimension.

In comparison, the similar GetString method returns a specified Recordset as a string.

Syntax

vararray=objRecordset.GetRows(rows,start,fields)

There are three optional parameters.
Parameter

Description

rows Optional. A GetRowsOptionEnum value that specifies the number of records to retrieve. Default is adGetRowsRest.

Note: If you omit this argument it will retrieve all records in the Recordset

start Optional. What record to start on, a record number or a BookmarkEnum value
fields Optional. If you want to specify only the fields that the GetRows call will return, it is possible to pass a single field name/number or an array of field names/numbers in this argument

Example


set conn=New ADODB.Connection
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "F:\Mydata\northwind.mdb"
set rs = New ADODB.recordset
rs.Open "Select * from Customers", conn

'The first number indicates how many records to copy
'The second number indicates what recordnumber to start on
varGetRowsArray=rs.GetRows(2,0)
rs.close
conn.close
 

GetRowsOptionEnum Values

Constant Value

Description

adGetRowsRest -1 Retrieves the rest of the records in the Recordset object
 

BookmarkEnum Values

Constant Value

Description

adBookmarkCurrent 0 Starts at the current record
adBookmarkFirst 1 Starts at the first record
adBookmarkLast 2 Starts at the last record