this.status = Convert.ToInt32(((this.db.GetParameterValue(com, "Status") == DBNull.Value) ? 0 : this.db.GetParameterValue(com, "Status")));
Status
是SQL Server存储过程的输出参数,但它始终返回0.
存储过程是:
CREATE procedure CandidatesloginMaster_CheckSecurityCredential
@CandidateID int output,
@Username varchar(25),
@Password varchar(25),
@Key1 varchar(25),
@key2 varchar(25),
@Status int output
AS
set NOCOUNT ON
BEGIN
BEGIN TRY
IF(@Status = 0)
BEGIN
IF exists(
select Username,Key1,key2
from CandidatesloginMaster
where Username = @Username AND
Key1 = @Key1 AND
Key2 = @key2
)
BEGIN
SET @Status = 1
SET @CandidateID = (SELECT CandidateID
from CandidatesloginMaster
where Username = @Username AND
Key1 = @Key1 AND
Key2 = @key2)
END
ELSE
BEGIN
SET @Status = 0
SET @CandidateID = 0
END
END
ELSE IF(@Status = 1)
BEGIN
UPDATE CandidatesloginMaster
SET Userpassword = @Password
where CandidateID =@CandidateID AND
Key1 = @Key1 AND
Key2 = @Key2
END
print @Status
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS ERROR_NO,
ERROR_MESSAGE() AS ERROR_MSG,
ERROR_LINE() AS ERROR_LINE_NO
END CATCH
END
我在SQL Server中直接运行程序,然后将状态值打印为1:
EXEC CandidatesloginMaster_CheckSecurityCredential
1, 'User', 'pwd', 'User123', 'User123', 0
但是通过代码后面的值相同,它总是返回0作为status(输出参数)。
答案 0 :(得分:0)
您将第一个和最后一个参数定义为OUT
个参数。这意味着在调用过程中存储到这些参数中的任何值都会传播到这些位置的变量。
这里的操作词是“变量”。它不能改变常数。
试试这个:
declare
@CandID int,
@Status int;
EXEC CandidatesloginMaster_CheckSecurityCredential
@CandID OUT, 'User', 'pwd', 'User123', 'User123', @Status OUT;
MSSQL,出于什么原因我无法理解,要求您不仅在定义过程时使用“out”,还要在调用过程时使用。