tags:

views:

19

answers:

1

I have a stored procedure call that goes like this:

using (OracleConnection con = new OracleConnection(ConfigurationManager.AppSettings["Database"]))
using (OracleCommand cmd = new OracleCommand("Package.Procedure", con))
{
   Int32 existsCount;

   cmd.CommandType = CommandType.StoredProcedure;
   cmd.Parameters.Add("successCount", OracleDbType.Int32, 0, ParameterDirection.InputOutput);
   cmd.Parameters.Add("BusinessId", OracleDbType.Int64, listRec.BusinessId, ParameterDirection.Input);

    con.Open();
    cmd.ExecuteScalar();
    con.Close();

    existsCount = Convert.ToInt32(cmd.Parameters["successCount"].Value);

    return (existsCount);
}

But on this line:

existsCount = Convert.ToInt32(cmd.Parameters["successCount"].Value);

It throws the Exception "Unable to cast object of type 'Oracle.DataAccess.Types.OracleDecimal' to type 'System.IConvertible'."

Any thoughts? Thanks.

+2  A: 

What about

existsCount = int.Parse(cmd.Parameters["successCount"].Value.ToString());
SchlaWiener
Right! Thanks, I kinda feel stupid now. But thanks a lot.
FelixMM
Well that's not stupid. Convert.To... should be the better choise if available. Since int.Parse() basically just parses the string value which should be a bit more overhead. However, one thing that might work too (didn't think about it in the first place) is: existsCount = (int)cmd.Parameters["successCount"].Valueif there is an explicit conversion provided by the Oracle lib.
SchlaWiener