NextRecordset 方法范例

该范例使用 NextRecordset 方法,查看使用了由三个独立 SELECT 语句组成的复合命令语句的记录集中的数据。

Public Sub NextRecordsetX()

   Dim rstCompound As ADODB.Recordset

   Dim strCnn As String

   Dim intCount As Integer

   ' 打开复合记录集。

      strCnn = "Provider=sqloledb;" & _

      "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "

   Set rstCompound = New ADODB.Recordset

   rstCompound.Open "SELECT * FROM authors; " & _

      "SELECT * FROM stores; " & _

      "SELECT * FROM jobs", strCnn, , , adCmdText

   ' 显示每一个 SELECT 语句的结果。

   intCount = 1

   Do Until rstCompound Is Nothing

      Debug.Print "Contents of recordset #" & intCount

      Do While Not rstCompound.EOF

         Debug.Print , rstCompound.Fields(0), _

            rstCompound.Fields(1)

         rstCompound.MoveNext

      Loop

      Set rstCompound = rstCompound.NextRecordset

      intCount = intCount + 1

   Loop

End Sub