I have field defined as float (price).
when I do the following command I get invalid cast.
reader.GetFloat(reader.GetOrdinal("price"));
I have to pull it with GetDouble.
reader.GetDouble (reader.getOrdinal("price"));
which works.
since it's defined as a float would that not make this an error.. or am I missing something?
GetFloat and GetDouble don't do any conversions. GetFloat expects a single precision and GetDouble a double precision value. Since the SQL Float is double precision you'll get an casting error with GetFloat. You could use GetFloat with a real field.
See "SQL Server Data Types and Their .NET Framework Equivalents" in books online for more info.
|||
When dealing with currency, why not create price as a sql type 'money'?
reader.GetDecimal (reader.getOrdinal("price")) would then work for you without throwing any casting exceptions.
No comments:
Post a Comment