asp中调用存储过程的问题

chenlinhaime1 2005-12-18 10:57:59
存储过程中三种返回类型在同一个存储过程一起使用,asp接收数据这样写:
set objCmd=server.CreateObject("adodb.command")
objCmd.ActiveConnection=Application("SqlSverdbs")
objCmd.CommandType=4
objCmd.CommandText="sp_test"
objCmd.Parameters.Refresh
set objRs=objCmd.execute
iRETURN_VALUE=objCmd.Parameters("@RETURN_VALUE").Value

问题是在asp中如有记录返回时,总是得不到返回值,没有记录集,就可以得到返回值。不知道为什么??记录可以得到,但是iRETURN_VALUE返回值总是得不到。

如果改成这样写,有执行了2次存储过程,使一些值被增加2次:
set objCmd=server.CreateObject("adodb.command")
objCmd.ActiveConnection=Application("SqlSverdbs")
objCmd.CommandType=4
objCmd.CommandText="sp_test"
objCmd.Parameters.Refresh
objCmd.Execute() --新增返回值
iRETURN_VALUE=objCmd.Parameters("@RETURN_VALUE").Value
set objRs=objCmd.execute --返回集

如何只执行一次就能同时返回记录集和返回值????????
...全文
97 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenlinhaime1 2005-12-18
  • 打赏
  • 举报
回复
请大家给我指出我的代码中哪里有问题拉??谢了。
chenlinhaime1 2005-12-18
  • 打赏
  • 举报
回复
兄弟,我是说如何在ASP下做拉,不是在sql查询分析器里??
dh20156 2005-12-18
  • 打赏
  • 举报
回复
简单写了个参考:
Create Procedure test
@r int output
As
Set @r = 1
Select top 1 * From shippers
Go

Declare @rv int
Exec test @rv output
Print @rv

Drop Procedure test

/*
ShipperID CompanyName Phone
----------- ---------------------------------------- ------------------------
1 Speedy Express (503) 555-9831

(所影响的行数为 1 行)

1
*/
chenlinhaime1 2005-12-18
  • 打赏
  • 举报
回复
感谢!风之石
dh20156 2005-12-18
  • 打赏
  • 举报
回复
原来要把记录集关闭后才可以取返回值:
Set cmd=server.CreateObject("Adodb.Command")
cmd.ActiveConnection = conn
cmd.CommandType = 4
cmd.commandText = "test"
cmd("@a") = 10
Set rs = cmd.execute()
for each i in rs.fields
response.write i&"<p>"
next
rs.close '关闭rs后才可以取返回值@r
rv = cmd("@r")
response.write rv&"<p>"
Set cmd = Nothing

结果:
1
Speedy Express

(503) 555-9831

10

存储过程将只执行一次,同时取出记录集和返回值。
dh20156 2005-12-18
  • 打赏
  • 举报
回复
执行两次了,SORRY,不正确。
dh20156 2005-12-18
  • 打赏
  • 举报
回复
TRY:
Create Procedure test
@a int,
@r int output
As
Set @r = @a
Select top 1 * From shippers
Go

ASP:
Set cmd=server.CreateObject("Adodb.Command")
cmd.ActiveConnection = conn
cmd.CommandType = 4
cmd.commandText = "test"
cmd("@a") = 10
Set rs = cmd.execute()
cmd.execute()
rv = cmd("@r")
response.write rv & "<p>"
do while not rs.eof
response.write rs.fields(0)&rs.fields(1)&rs.fields(2)&"<p>"
rs.MoveNext
Loop
Set cmd = Nothing

结果:
10
1Speedy Express(503) 555-9831
chenlinhaime1 2005-12-18
  • 打赏
  • 举报
回复
顶。

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧