在经典 ASP 中使用存储过程 .. 执行并获取结果 [英] Using Stored Procedure in Classical ASP .. execute and get results
问题描述
我一整天都在试图解决这个问题,但它似乎对我不起作用.我想执行一个命令并将结果返回到记录集.
I tried to solve this all day long but it doesn't seem to work for me. I would like to execute a command and get the result back to a recordset.
问题是两件事之一:要么我得到一个空的响应,要么我的代码有问题.我确信这个命令应该从数据库中获取几行.我在循环中添加了 response.write
,但它们从不打印.
The problem is one of two things: either I'm getting an empty response or there is a problem with my code. I know for sure that this command should fetch few lines from the DB. I added response.write
inside the loop, but they are never printed.
代码如下:
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=X;DATABASE=Y;UID=Z;PWD=W;"
Set objCommandSec = CreateObject("ADODB.Command")
With objCommandSec
Set .ActiveConnection = Conn
.CommandType = 4
.CommandText = "usp_Targets_DataEntry_Display"
.Parameters.Append .CreateParameter("@userinumber ", 200, 1, 10, inumber)
.Parameters.Append .CreateParameter("@group ", 200, 1, 50, "ISM")
.Parameters.Append .CreateParameter("@groupvalue", 200, 1, 50, ismID)
.Parameters.Append .CreateParameter("@targettypeparam ", 200, 1, 50, targetType)
End With
set rs = Server.CreateObject("ADODB.RecordSet")
rs = objCommandSec.Execute
while not rs.eof
response.write (1)
response.write (rs("1_Q1"))
rs.MoveNext
wend
response.write (2)
已编辑修改代码后,按照@Joel Coehoorn的回答,解决方法是:
EDITED After revising the code, following @Joel Coehoorn answer, the solution is:
set rs = Server.CreateObject("ADODB.RecordSet")
rs.oppen objCommandSec
而不是...
set rs = Server.CreateObject("ADODB.RecordSet")
rs = objCommandSec.Execute
推荐答案
看了几分钟,我已经很长时间使用经典的 asp 了,但我做到了看三件事:
Looked at this for a few minutes, and it's been a long time since I've worked with classic asp, but I did see three things to look at:
- 在调用
objCommandSec.Execute
之前是否需要Open
连接? - 您能否尝试在循环内写出一个字符串文字,它完全不依赖于记录集...只是您实际上是在循环代码,所以看看记录是否返回到记录集.
- 您是否检查过 html 源代码,看看是否有格式错误的 html 隐藏了您的结果?我记得在经典 asp 循环中的表中发生了几次这种情况,其中数据会以某种方式隐藏在两行之间,或者错误位置的结束表标记会结束表,并且后面的行将不可见.
这篇关于在经典 ASP 中使用存储过程 .. 执行并获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!