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