DAAB GetParameterValue does not return output parameter value
I have a stored procedure that recives as paramter as OUTPUT paramter. The store procedure sets its value. I have the following code in C# application. But I am not getting the value in application (the 开发者_运维知识库output is returned as zero). What is the missing link here?
CREATEPROCEDURE [dbo].aspInsertZipCode
(
@CountOfUnchangedZipCode AS INT=0 OUTPUT
)
AS
BEGIN
SET NOCOUNT ON
SET @CountOfUnchangedZipCode = 13
END
In the application, code is as follows
DbCommand cmd = db.GetStoredProcCommand("aspInsertZipCode");
cmd.CommandTimeout = 0;
db.AddOutParameter(cmd, "CountOfUnchangedZipCode", DbType.String, 1000);
The execution happens ...
int TempUnchageZipCount = Convert.ToInt32(db.GetParameterValue(cmd, "@CountOfUnchangedZipCode"));
Add to your SP:
RETURN @CountOfUnchangedZipCode
Otherwise you could use something like this after executing the command in your code:
var TempUnchageZipCount = (int) cmd.Parameters[0].Value;
精彩评论