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

解决方案 »

  1.   

    在存储过程开始的时候先set nocount on在最后一个select之前 set nocount off
      

  2.   

    ----具体见sqlserver联机帮助set nocountSET NOCOUNT
    使返回的结果中不包含有关受 Transact-SQL 语句影响的行数的信息。语法
    SET NOCOUNT { ON | OFF }注释
    当 SET NOCOUNT 为 ON 时,不返回计数(表示受 Transact-SQL 语句影响的行数)。当 SET NOCOUNT 为 OFF 时,返回计数。即使当 SET NOCOUNT 为 ON 时,也更新 @@ROWCOUNT 函数。当 SET NOCOUNT 为 ON 时,将不给客户端发送存储过程中的每个语句的 DONE_IN_PROC 信息。当使用 Microsoft® SQL Server™ 提供的实用工具执行查询时,在 Transact-SQL 语句(如 SELECT、INSERT、UPDATE 和 DELETE)结束时将不会在查询结果中显示"nn rows affected"。如果存储过程中包含的一些语句并不返回许多实际的数据,则该设置由于大量减少了网络流量,因此可显著提高性能。SET NOCOUNT 设置是在执行或运行时设置,而不是在分析时设置。