DAAB GetParameterValue does not return output parameter value

两盒软妹~` 提交于 2019-12-13 06:34:37

问题


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"));

回答1:


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;


来源:https://stackoverflow.com/questions/6819535/daab-getparametervalue-does-not-return-output-parameter-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!