Specified cast not valid on decimal & double datatypes

N

.Net Sports

I have a variable that is part of my dataset (a double int datatype),
and I need to use this variable in an ItemDataBound for a datagrid.
When debugging and looking at the StackTrace, the Specified cast not
valid error is pointing to my double int that i need to assign to
'price' , which was declared as a Decimal in my ItemDataBound function:

Decimal price;
price = (decimal)(rowData["dblTotalVolume"]);

the price variable will be used on my datagrid as a totals figure when
adding up a datagrid column , so I'm using it in an ItemDataBound
function. I'm wondering how to change dbleTotalVolume so I can use it
in this context.
Thanks
netsports
 
J

John Rivers

try this:

price = (decimal)(int)(rowData["dblTotalVol­ume"]);

where (int) is the actual type of your column

you can't cast from object through to another type without first
unwrapping the current type

this is because there are situations where the runtime would have have
no way of knowing
which class in a tree of derived classes to choose as the default

read up more on OO programming to get the hang of this type of thing



(maybe you are using "long" not "int")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top