locked
Enterprize library 4.1 getting output parameter after adding record in db, plz guide RRS feed

  • Question

  • User852864959 posted

    Hi,

    I need to get output parameter (flag) from db after saving record in database. I am using Microsoft Enterprise Library 4.1 for DB. I am inserting record using I Data reader.

    Please guide

    Thanks

    <input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">

    Monday, January 11, 2010 4:25 AM

All replies

  • User7547248 posted

    Here is an example. You can refer this.


    int retValue = int.Parse(db.GetParameterValue(dbCommandObj , "ParamName").ToString());


    Where db -> Object of Database

    dbCommandObj - > object of DbCommand




    Monday, January 11, 2010 5:32 AM
  • User852864959 posted

    Hi,

    thanks for replaying, I m not using dbcommand, I am using I data reader. can u plz advice ?

    thanks

    <input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">

    Monday, January 11, 2010 6:34 AM
  • User94749686 posted

    hi.

    let's say you are passing assay of parameters named  arParms.

    then you can use arParms[N].Value; After ExecuteReader Method.here N is index of output parameter in array of parameters.


    thanks.

    Monday, January 11, 2010 6:47 AM
  • User852864959 posted

    thanks HerryAtHotmail,

    Actually I am not using DBCommand so not passing parameter array. I am using IDataReader wiht Database class

    so it is just like:

    using (IDataReader reader = db.ExecuteReader("sp_GetArtists", null, 2,null))
          

    It is good way as it allow passign parameters without declaring them but I am not getting how to get output parameter

    from it.

    Please guide

    thanks


    Tuesday, January 12, 2010 6:51 AM
  • User-37275327 posted

    Try this

                Dim db As Database = DatabaseFactory.CreateDatabase(CWB_DBCONNECTION_STRING)  // This is name of connection string in the web.config file

                 Dim DBC As DbCommand = db.GetStoredProcCommand(SALES_INSERT)
                db.AddInParameter(DBC, "@SalesID", DbType.Int64, Me.SalesID)
                db.AddInParameter(DBC, "@CustomerID", DbType.Int64, Me.CustomerID)          

                db.AddOutParameter(DBC, "@CurrentSalesID", DbType.Int64, 0)
                db.ExecuteNonQuery(DBC, transaction)

                Dim CurrentSalesID as int64

                  CurrentSalesID = Convert.ToInt64(db.GetParameterValue(DBC, "@CurrentSalesID").ToString())

    I put the value of currentSaleID in to a variable. Rember create SP as follows


    CREATE PROCEDURE [dbo].[Sales_Insert]
        (@SalesID bigint,
         @CustomerID     bigint,   
         @CurrentSalesID bigint output)

    AS

    INSERT INTO [tblSales]
         ([CustomerID] )
     
    VALUES
         (@CustomerID,)


    set @CurrentSalesID=SCOPE_IDENTITY()


    Wednesday, February 10, 2010 12:14 PM