Using Arrays and the GetRows Method

We'll often find ourselves wanting to repetitively scan through a recordset searching for different sets of data. This can easily be achieved using dynamic cursor recordsets or multiple SQL queries, but both are less that ideal in the efficiency stakes. There is a far more efficient method at our disposal. ADO provides us with a method that enables us to easily convert a

Recordset
object into an array—which can then be scanned efficiently using ordinary code. This is the syntax:

variantarray

=
recordset
.GetRows(
NumberOfRows
)

The

GetRows
method takes a
Recordset
object and converts it into the equivalent multi-dimensioned array. Just as we'd expect, a recordset consisting of three fields and ten records is converted to a 3 x 10 array—think of the first dimension being horizontal and the second vertical, just like a normal table is displayed in Access or SQL Server. The NumberOfRows argument is optional, and specifies the number of records to retrieve. This argument is frequently used on ordered recordsets, where the record ordering has been set by a defined table index, or an
ORDER
BY
clause in the SQL query. You'll see the
GetRows
method used in the Forum case study chapter later in the book.

© 1997 by Wrox Press. All rights reserved.