How to return multiple recordsets in a single execution using ADODB?

a 夏天 提交于 2019-12-01 05:39:01

问题


I need to iterate through multiple recodsets produced by a single query.

However my current connection does not seem to support doing this. So when I do .NextRecordset I get the message:

Current provider does not support returning multiple recordsets from a single execution

This is my connection string:

DB_CONNECTION = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Forecasting;Integrated Security=SSPI;"
Call Conn.Open(DB_CONNECTION)

What must I do to be able to use .NextRecordset?


回答1:


Set the CursorLocation to adUseServer (instead of '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


来源:https://stackoverflow.com/questions/34662952/how-to-return-multiple-recordsets-in-a-single-execution-using-adodb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!