locked
How to get the OUTPUT parameter using Enterprise library RRS feed

  • Question

  • User-1571110992 posted

    Hi All,

    I want to take output from sp using Enterprise library. I wrote following code  but, giving me error "Conversion from string "ss" to type 'Integer' is not valid."

    Dim OutputOperation As String = "ss"
            Dim db As Database = DatabaseFactory.CreateDatabase("IndicatorDB")
            Dim cmd As DbCommand = db.GetStoredProcCommand("sp_CheckStatusBeforeLoad")
            db.AddInParameter(cmd, "session_id", DbType.Int32, session_id)
            db.AddOutParameter(cmd, "OutputOperation", DbType.String, OutputOperation)
            db.ExecuteNonQuery(cmd)
            OutputOperation = db.GetParameterValue(cmd, "OutputOperation")
            Return OutputOperation

     SP

    Alter PROCEDURE sp_CheckStatusBeforeLoad      
        
    @session_id int,    
    @OutputOperation varchar(10) OUTPUT  
    AS      
    BEGIN      
     -- SET NOCOUNT ON added to prevent extra result sets from      
     -- interfering with SELECT statements.      
     SET NOCOUNT ON;      
       
    If Exists(select 1    
    from dbo.indicator_definition AS TARGET    
      inner join dbo.indicator_definition_preLoad AS SOURCE      
      ON (TARGET.[display_type_id] = SOURCE.[display_type_id]     
      and TARGET.measurement_type_id=SOURCE.measurement_type_id     
      and TARGET.internal_id=SOURCE.internal_id )where 1=1 and session_id= @session_id)--@session_id))    
          
      SET @OutputOperation=@OutputOperation+'update'    
    else    
     set @OutputOperation=@OutputOperation+'insert'     
        
    --select @OutputOperation    
          
    END


    Wednesday, July 10, 2013 4:25 PM

Answers

  • User-1571110992 posted
     Dim OutputOperation As String = 6
            Dim db As Database = DatabaseFactory.CreateDatabase("IndicatorDB")
            Dim cmd As DbCommand = db.GetStoredProcCommand("sp_CheckStatusBeforeLoad")
            db.AddInParameter(cmd, "session_id", DbType.Int32, session_id)
            db.AddOutParameter(cmd, "OutputOperation", DbType.String, Convert.ToString(OutputOperation))
            db.ExecuteNonQuery(cmd)
            OutputOperation = db.GetParameterValue(cmd, "OutputOperation")
            Return OutputOperation

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 10, 2013 4:50 PM