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
object into an array—which can then be scanned efficiently using ordinary code. This is the syntax:Recordset
variantarray
recordset=
NumberOfRows.GetRows(
)
The
method takes a GetRows
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 Recordset
ORDER
clause in the SQL query. You'll see the BY
method used in the Forum case study chapter later in the book.GetRows