CADORecordset.GetRowsmethod
Retrieves multiple records of a `Recordset` object into an array.
Syntax
FUNCTION GetRows (BYVAL Rows AS LONG = adGetRowsRest, BYREF dvStart AS DVARIANT = "", BYREF dvFields AS DVARIANT = "") AS SAFEARRAY PTR
Parameters
| Name | Description | |
|---|---|---|
Rows | Optional. A GetRowsOptionEnum value that indicates the number of records to retrieve. The default is adGetRowsRest. | |
dvStart | Optional. A string value or Variant that evaluates to the bookmark for the record from which the GetRows operation should begin. You can also use a BookmarkEnum value. | |
dvFields | Optional. A Variant that represents a single field name or ordinal position, or an array of field names or ordinal position numbers. ADO returns only the data in these fields. | |
adBookmarkCurrent | Starts at the current record. | |
adBookmarkFirst | Starts at the first record. | |
adBookmarkLast | Starts at the last record. |
Return value
SAFEARRAY. The array of records.
Description
Retrieves multiple records of a Recordset object into an array.
Remarks
Use the GetRows method to copy records from a Recordset into a two-dimensional array. The first subscript identifies the field and the second identifies the record number. The array variable is automatically dimensioned to the correct size when the GetRows method returns the data.
If you do not specify a value for the Rows argument, the GetRows method automatically retrieves all the records in the Recordset object. If you request more records than are available, GetRows returns only the number of available records.
If the Recordset object supports bookmarks, you can specify at which record the GetRows method should begin retrieving data by passing the value of that record's Bookmark property in the Start argument.
If you want to restrict the fields that the GetRows call returns, you can pass either a single field name/number or an array of field names/numbers in the Fields argument.
After you call GetRows, the next unread record becomes the current record, or the EOF property is set to True if there are no more records.
Example
#include once "AfxNova/CADODB.inc" #include "AfxNova/DSafeArray.inc" USING AfxNova
' // Open the connection DIM pConnection AS CAdoConnection pConnection.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=biblio.mdb")
' // Open the recordset DIM pRecordset AS CAdoRecordset DIM dwsSource AS DWSTRING = "SELECT TOP 20 * FROM Publishers ORDER BY Name" DIM hr AS HRESULT = pRecordset.Open(dwsSource, pConnection, adOpenKeyset, adLockOptimistic, adCmdText)
' // GetRows returns a pointer to a two-dimensional safe array ' // that we are going to attach to an instance of the CSafeArray class DIM dsa AS DSafeArray = DSafeArray(pRecordset.GetRows, TRUE)
' // Print the contents of the safe array FOR j AS LONG = dsa.LBound(2) TO dsa.UBound(2) FOR i AS LONG = dsa.LBound(1) TO dsa.UBound(1)
PRINT dsa.GetVar(i, j)
NEXT PRINT NEXT
' // === Close the recordset and the connection ' // If you don't close them, they will be closed when the application ends pRecordset.Close pConnection.Close
Reference
- Include file
CADORecordset.inc - Defined in AfxNova/CAdoRecordset.inc:1071
- Documented in Databases/ADO Classes/CAdoRecordset Class.md
- Topic: CADORecordset Class