Search code examples
c#.netasp.netado.netenterprise-library

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

Solution

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