views:

166

answers:

1

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
+2  A: 

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.

Oded
i changed it to command object and parameters. But i get 0 record count when i execute them
rs
Are you certain the recordsets returned are not empty?
Oded
yes i checked using response.write(rs.recordcount) and i get -1
rs
This does not mean the recordset has something in it. rs.RecordCount would return -1 when ADO cannot determine the number of records or if the provider or cursor type does not support RecordCount.
Oded
ok, but if i want to do this r1 = rs.GetString(, , ", ", "<BR>" )how should i check if records are there?
rs
i used if not rs.eof to check if it has values but i need to get count also
rs
http://msdn.microsoft.com/en-us/library/ms676701%28VS.85%29.aspx
Oded