將你的程序修改成這樣:CREATE PROCEDURE sp_psw (@UserId [varchar](15), @UserPsW [varchar](20), @truepassword int out ) AS declare @oldpsw varchar(20) select @oldpsw=userpassword from tpeople where userid=@UserId print(@oldpsw) select @UserPsW=encrypt(@UserPsW) print(@UserPsW) if @oldpsw=@UserPsW set @truepassword = 1 else set @truepassword = 2 return @truepassword
--然後在SQL Server的Query Analyzer中這樣執行: declare @nprint int set @nprint = 0 exec sp_psw 'aaa','bbb',@nprint --其中'aaa','bbb'為你具體的值 print @nprint
给一段用VBScript调用存储过程的的代码,希望有启示。 Dim lComStat As Command Set lComStat = CreateObject("adodb.command") lComStat.ActiveConnection = gConnGeneral lComStat.CommandType = adCmdStoredProc lComStat.CommandText = "存储过程名" lComStat.Parameters(1) = 参数1 lComStat.Parameters(2) = 参数2
lComStat.Execute
If lComStat.Parameters(0) < 0 Then ‘lComStat.Parameters(0)为返回值 MsgBox "数据入库错误,请与系统生产商取得联系!", vbOKOnly, "信息提示!" Exit Sub End If
是這個過程的傳入值.
和return的值沒有關係.
我以为truepassword是返回值。我不能用set truepassword=conn.execute(...)语句来获得返回值啊。
fstruserid和fstrUserPassword是传入的参数。
那麼修改一下.CREATE PROCEDURE sp_psw
(@UserId [varchar](15),
@UserPsW [varchar](20),
@truepassword int out )
AS
declare @oldpsw varchar(20)
select @oldpsw=userpassword from tpeople where userid=@UserId
select @UserPsW=encrypt(@UserPsW)
if @oldpsw=@UserPsW
set @truepassword = 1
else
set @truepassword = 2
return @truepassword
調用程序為:
set conn= server.CreateObject("ADODB.CONNECTION")
conn.Open Application("system_ConnectionString") ‘包含存储过程的数据库strsql="sp_psword '"&fstruserid&"','"&fstrUserPassword&"',&truepassword&"
call conn.Execute (strsql)然後看看truepassword這個值是不是你想要的.
我把程序改成这样试也不成。
CREATE PROCEDURE sp_psw
@UserId [varchar](15),
@UserPsW [varchar](20),
@truepassword int output
AS
declare @oldpsw varchar(20)
select @oldpsw=userpassword from tpeople where userid=@UserId
select @UserPsW=encrypt(@UserPsW)
if @oldpsw=@UserPsW
return 1
else
return 2
为什么,为什么?他欺负我是新手!!!我哭哭哭.....我怎么一不留神就做了程序员呢,我是白痴。
(@UserId [varchar](15),
@UserPsW [varchar](20),
@truepassword int out )
AS
declare @oldpsw varchar(20)
select @oldpsw=userpassword from tpeople where userid=@UserId
print(@oldpsw)
select @UserPsW=encrypt(@UserPsW)
print(@UserPsW)
if @oldpsw=@UserPsW
set @truepassword = 1
else
set @truepassword = 2
return @truepassword
declare @nprint int
set @nprint = 0
exec sp_psw 'aaa','bbb',@nprint --其中'aaa','bbb'為你具體的值
print @nprint
Dim lComStat As Command
Set lComStat = CreateObject("adodb.command")
lComStat.ActiveConnection = gConnGeneral
lComStat.CommandType = adCmdStoredProc
lComStat.CommandText = "存储过程名"
lComStat.Parameters(1) = 参数1
lComStat.Parameters(2) = 参数2
lComStat.Execute
If lComStat.Parameters(0) < 0 Then ‘lComStat.Parameters(0)为返回值
MsgBox "数据入库错误,请与系统生产商取得联系!", vbOKOnly, "信息提示!"
Exit Sub
End If
一般情况下返回值为0表示存储过程执行正确,否则有问题。
当然你也可以自己定义返回值,象上面那样。
@truepassword int out 是一个输出参数,它可以是任何SQL的数据类型。
return 1设置一个存储过程的返回值,只能返回一个整数,注意-1到-99为系统返回值。在ASP中读取输出参数和返回值是不同的:
1。读取输出参数
cmd.Parameters.Append cmd.Parameters.CreateOarameter("truepassword",adInteger,adParamOutput) '其中的truepassword必须与存储过程中的out参数一致
......
cmd.execute
response.write cmd("truepassword") '显示输出参数2.读取存储过程返回值
注意:在读取存储过程返回值以前,你必须关闭含有数据行的recordsetcmd.Parameters.Append cmd.Parameters.CreateOarameter("truepassword",adInteger,adParamReturnValue) 'truepassword是任意的名称
......
set rs=cmd.execute
......
rs.close '必须的
response.write cmd("truepassword")
在Query Analyzer中這樣執行:
declare @nprint int
set @nprint = 0
exec sp_psw 'aaa','bbb',@nprint output --其中'aaa','bbb'為你具體的值
print @nprint