开发者

DAAB GetParameterValue does not return output parameter value

开发者 https://www.devze.com 2023-03-22 15:13 出处:网络
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 (t

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号