Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Specified cast not valid on decimal & double datatypes

Thread Tools

Specified cast not valid on decimal & double datatypes

.Net Sports
Posts: n/a
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.

Reply With Quote
John Rivers
Posts: n/a

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")

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: specified cast is not valid. Why not? Alan Silver ASP .Net 5 02-15-2005 08:08 PM
User Control - InvalidCastException: Specified cast is not valid Ajit ASP .Net 1 04-24-2004 09:28 PM
I get the following error ( Specified cast is not valid ) with Server.Transfer Andrew ASP .Net 0 08-12-2003 08:26 PM
System.InvalidCastException: Specified cast is not valid. Arjen ASP .Net 1 08-06-2003 03:26 AM
System.InvalidCastException: Specified cast is not valid Floela ASP .Net 3 07-10-2003 10:36 AM