我需要遍历单个查询生成的多个记录集。
但是我目前的连接似乎不支持这样做。因此,当我执行 .NextRecordset 时,我收到消息:
Current provider does not support returning multiple recordsets from a single execution
这是我的连接字符串:
DB_CONNECTION = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Forecasting;Integrated Security=SSPI;"
Call Conn.Open(DB_CONNECTION)
我必须做什么才能使用 .NextRecordset?
最佳答案
将 CursorLocation 设置为 adUseServer (而不是 'client side' )
Set RS = New ADODB.Recordset
strSQL = "Select * from States; Select * from Countries;"
With RS
.CursorLocation = adUseServer
.ActiveConnection = DB_CONNECTION
.CursorType = adOpenStatic
.Open strSQL
End With
Do
If Not RS.EOF Then
'do something
End If
Set RS = RS.NextRecordset
If RS Is Nothing Then
Exit Do
End If
Loop Until RS.State = adStateClosed
关于sql - 如何使用 ADODB 在一次执行中返回多个记录集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34662952/