GetRows Method Example

This example illustrates use of the GetRows method to fetch rows from an rdoResultset into a variant array. The code opens a connection to a remote data source and creates an rdoQuery object that requires a single parameter. The GetRowsNow procedure executes the query with a user-supplied parameter and uses GetRows to fetch the rows from the result set.

Option Explicit
Dim er As rdoError
Dim cn As New rdoConnection
Dim qy As New rdoQuery
Dim rs As rdoResultset
Dim RowBuf As Variant
Dim RowsReturned As Integer
Dim i As Integer
Dim Ans As Integer

Private Sub GetRowsNow_Click()
qy(0) = StateWanted
rs.Requery

Do Until rs.EOF
   List1.Clear
   RowBuf = rs.GetRows(5)      'Get the next 5 rows
   RowsReturned = UBound(RowBuf, 2) + 1
   For i = 0 To RowsReturned - 1
      List1.AddItem RowBuf(0, i) & ":" & RowBuf(1, i)
   Next i
   Ans = MsgBox("Press Ok to see next 5 rows " _
      &" or Cancel to quit", vbOKCancel)
   If Ans = vbOK Then Else Exit Sub
Loop
End Sub

Private Sub Form_Load()
cn.CursorDriver = rdUseOdbc
cn.Connect = "uid=;pwd=;server=SEQUEL;" _
   driver={SQL Server};database=pubs;dsn='';"
cn.EstablishConnection
With qy
   .Name = "GetRowsQuery"
   .SQL = "Select * from Titles T, Publishers P " _
   & " Where T.Pub_ID = P.Pub_ID " _
   & " and P.State = ?"
   .RowsetSize = 1
   Set .ActiveConnection = cn
   .rdoParameters(0) = "CA"
   Set rs = .OpenResultset(rdOpenKeyset, _
      rdConcurRowver)
End With
End Sub