我的SQL存储过程代码是:
create procedure sysuser_pro
@login varchar(12),
@password varchar(12),
@return int=0 output
as
begin transaction
declare @lg varchar(12)
select @lg =username from sysuser where username = @login
if (@lg = @login)
begin
rollback transaction
set @return=0
end
else
begin
insert into sysuser values(@login,@password)
commit transaction
set @return=1
end
我VB的执行代码是:
Dim strID As String
Dim strPass As String
Dim i As Integer
Set sql_pro = New ADODB.Command
Set sql_pro.ActiveConnection = sql_conn
sql_pro.CommandType = adCmdStoredProc '设置这个属性优化了该命令的执行。
sql_pro.CommandText = "sysuser_pro" '设置Command对象源
strID = Trim(txtID)
strPass = Trim(txtPassword)
Set Param = sql_pro.CreateParameter("varin", adVarChar, adParamInput, 50, strID)
sql_pro.Parameters.Append Param 'Append将对象添加到该集合,
Set Param = sql_pro.CreateParameter("varin", adVarChar, adParamInput, 50, strPass)
sql_pro.Parameters.Append Param
Set Param = sql_pro.CreateParameter("varin", adInteger, adParamOutput, 4)
sql_pro.Parameters.Append Param
Set sql_re = sql_pro.Execute
'MsgBox "此节点的名称为: " & Rs(4).Value
MsgBox "名称为: " & sql_pro.Parameters(0) '显示返回参数值
MsgBox "名称为: " & sql_pro.Parameters(1)
MsgBox "名称为: " & sql_pro.Parameters(2)
i = sql_pro.Parameters(2)
If i = 0 Then
MsgBox "执行不成功"
Else
MsgBox "执行成功"
End If
现在的问题是,无论存不存在那条数据,VB他只能取到0的值,不知道为什么,很郁闷!
而且在SQL查询分析器中 执行存储过程,一切OK,一到VB掉用,就出现问题,反正不管有没有,都是返回执行不成功,而且sql_pro.Parameters(2) 总是为空值 求教啊!