Reading multiple recordsets

2019-08-07 23:03发布

问题:

I have a Stored proc which returns 6 select statement results. I'm trying to use one record set to execute sp and get records for each select statement but i get 0 or empty records when i read them,

How can i query record set with multiple select statements from stored procedure?

ex:

Set rs = Server.CreateObject("ADODB.Recordset")     
strSql = "Exec [dbo].[xyz] '"&param1&"', '"&param2&"', '"&param3& "'"   
rs.open strSql,CN,3,3       

    Do While Not rs.EOF 
        if rs.recordcount > 0 then
            r1 = rs.GetString(, , ", ", "<BR>" ) 
        else
            r1 = 0
        end if
    rs.MoveNext
    Loop    

    Set rs = rs.NextRecordset()
        Do While Not rs.EOF 
        if rs.recordcount > 0 then
            r2 = rs.GetString(, , ", ", "<BR>" ) 
        else
            r2 = 0
        end if
    rs.MoveNext
    Loop

回答1:

rs.NextRecordset() is the right way to get to the next recordset returned from a stored procedure or other command, so your code snipped should work.

What is not working for you?

As an aside, I hope the strSql variable is not constructed the way you posted (strSql = "Exec [dbo].[xyz] '"&param1&"', '"&param2&"', '"&param3& "'"), as this is a clear SQL Injection vulnerability.