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
可以實現的。
假如你的前端程式是用ADO連的話,可以把兩句Select語句擺在一起,它就會返回兩個Recordset.
例:
Dim rs As New ADODB.Recordset
Dim tmp As New ADODB.Recordset
Dim Conn as New Adodb.Connection
Conn.CursorLocation = adUseClient
Conn.Open "Provider=SQLOLEDB;UID=sa;PWD=;Initial Catalog=Var2000;Data Source=NIPSAN"
rs.Open "Select * From tblStock; Select * From tblStockSub", Conn, adOpenStatic, adLockBatchOptimistic
Set tmp = rs.NextRecordset
MsgBox rs.RecordCount
MsgBox tmp.RecordCount
Set Conn = Nothing