issue with table reading and casting

issue with table reading and casting

Postby memoran » Tue 27 Mar 2007 21:09

I have a simple table:

CREATE TABLE RLAPPVFL.MODEL
(
MODELID INTEGER NOT NULL,
MODELNAME VARCHAR2(20 BYTE) NOT NULL,
BASEPRICE NUMBER(7,2) NOT NULL
)

And I am trying to itterate through a OracleDataReader and process the data in to an object.

public class Model
{
public int ModelId;
public string ModelName;
public decimal BasePrice;
public Model(int id, string name, decimal price)
{
ModelId = id;
ModelName = name;
BasePrice = price;
}
public override string ToString()
{
return ModelId + " " + ModelName + " "
+ string.Format("{0:C}", BasePrice);
}
}

My issue is that when I read it out, I get an error reading the data due to a casting issue. I get an InvalidcastException - When casting from a number, the value must be a number less than infinity.

Model m = new Model((int) (decimal) row["ModelId"],(string) row["ModelName"], (decimal) row["BasePrice"]);

Why am I getting this error on the BasePrice field? I thought that all number columns are brought back as Oracle Number types.

It works if I cast it from a double.

Model m = new Model((int) (decimal) row["ModelId"],(string) row["ModelName"], (decimal) (double) row["BasePrice"]);

Any help or an explanation would be greatly appreciated.

Mark
memoran
 
Posts: 3
Joined: Mon 08 Nov 2004 23:49
Location: Phoenix, AZ

Postby Alexey » Wed 28 Mar 2007 06:33

This is a designed behaviour. The value of type NUMBER(7,2) is to be casted to DOUBLE, that's way the error occurs using first way.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for Oracle