读取多个记录集
我有一个存储过程,它返回 6 个 select 语句结果。 我正在尝试使用一个记录集来执行 sp 并获取每个 select 语句的记录 但当我读取它们时,我得到 0 或空记录,
我如何查询记录集 多个 select 语句来自 存储过程?
前任:
Set rs = Server.CreateObject("ADODB.Recordset")
strSql = "Exec [dbo].[xyz] '"¶m1&"', '"¶m2&"', '"¶m3& "'"
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
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] '"¶m1&"', '"¶m2&"', '"¶m3& "'"
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
rs.NextRecordset()
是获取从存储过程或其他命令返回的下一个记录集的正确方法,因此您的代码片段应该可以工作。什么不适合你?
顺便说一句,我希望
strSql
变量不是按照您发布的方式构造的 (strSql = "Exec [dbo].[xyz] '"¶m1&"', '"& ;param2&"', '"¶m3& "'"
),因为这是一个明确的 SQL 注入 漏洞。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] '"¶m1&"', '"¶m2&"', '"¶m3& "'"
), as this is a clear SQL Injection vulnerability.