ADO 2.7 Samples

NextRecordset Method Example (VB)

This example uses the NextRecordset method to view the data in a recordset that uses a compound command statement made up of three separate SELECT statements.

'BeginNextRecordsetVB

    'To integrate this code
    'replace the data source and initial catalog values
    'in the connection string

Public Sub NextRecordsetX()

    ' connection and recordset variables
   Dim rstCompound As ADODB.Recordset
   Dim Cnxn As ADODB.Connection
   Dim strCnxn As String
   Dim SQLCompound As String
   
   Dim intCount As Integer

   ' Open connection
   Set Cnxn = New ADODB.Connection
   strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=pubs;User Id=sa;Password=;"
   Cnxn.Open strCnxn

   ' Open compound recordset
   Set rstCompound = New ADODB.Recordset
   SQLCompound = "SELECT * FROM Authors; " & _
      "SELECT * FROM stores; " & _
      "SELECT * FROM jobs"
   rstCompound.Open SQLCompound, Cnxn, adOpenStatic, adLockReadOnly, adCmdText

   ' Display results from each SELECT statement
   intCount = 1
   Do Until rstCompound Is Nothing
      Debug.Print "Contents of recordset #" & intCount
      
      Do Until rstCompound.EOF
         Debug.Print , rstCompound.Fields(0), rstCompound.Fields(1)
         rstCompound.MoveNext
      Loop
   
      Set rstCompound = rstCompound.NextRecordset
      intCount = intCount + 1
   Loop
   
    ' clean up
   rstCompound.Close
   Cnxn.Close
   Set rstCompound = Nothing
   Set Cnxn = Nothing
   
End Sub
'EndNextRecordsetVB

See Also

NextRecordset Method | Recordset Object

© 1998-2001 Microsoft Corporation. All rights reserved.