1 Reply Latest reply: Aug 20, 2009 10:48 AM by 456311 RSS

    Convert OracleDbType.Decimal to C# decimal

    456311
      Hi all,
      Iam calling ORACLE function and I have a problem with converting OracleDbType.Decimal to System.Decimal. I have the following code:

      ...(class)
      public decimal speed;
      OracleCommand cmd = new OracleCommand("GETNORM", dataCa.connection);
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.Parameters.Add("return", OracleDbType.Int32).Direction = ParameterDirection.ReturnValue;
      cmd.Parameters.Add("CODE", OracleDbType.Decimal).Value = idSubject;
      cmd.Parameters.Add("OUTSPEED", OracleDbType.Decimal).Direction = ParameterDirection.Output;
      cmd.ExecuteNonQuery();

      this.speed = (Decimal)cmd.Parameters["OUTSPEEDVALUE"].Value;
      ...

      The last line causes runtime error: Specified type-cast is invalid (I'm translating from Czech language). In VS2008 debug I see, that "cmd.Parameters["OUTSPEEDVALUE"].Value" has value (OUTSPEEDVALUE = 62).
      My question is: How can I assign value from an Oracle parameter to .NET (C#) variable.
      I'm unhappy 2 days.
      Thanks
      Martin