Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following line of code in my app:

C#
packsize.CompanyPrice = (decimal)Reader["CompanyPrice"];


but it raises an error "when casting from a number, the value must be a number less than infinity".

i have set database datatype as double, but in my app it is decimal. Does it cause this problem?

What i am missing here ??

Regards
SKPaul
Posted
Updated 13-Aug-12 0:57am
v2
Comments
bbirajdar 13-Aug-12 6:34am    
Congrats.. You were able to generate the value of 'infinity'...A great achievement . Why don't you assign the value of 'Reader["CompanyPrice"]' into a object type variable and check yourself and let us know the value of 'infinity'.. This will complete the question as well..
Mehdi Gholam 13-Aug-12 6:34am    
Put a breakpoint on the line and watch the value for Reader["CompanyPrice"] to see what your data is.
Timberbird 13-Aug-12 6:36am    
Put a breakpoint on that line and check Reader["CompanyPrice"] value when debugging to see what you're trying to cast. BTW, why not Convert.ToDecimal(Reader["CompanyPrice"])?

1 solution

Looks like your column is of type float or real or some other large number. Larger than decimal can hold.
I would try the debugger to see what is actually returned by your database.

See this article on how to debug: Advanced Debugging in Visual Studio[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900