Specified cast not valid on decimal & double datatypes

Discussion in 'ASP .Net' started by .Net Sports, Aug 31, 2005.

  1. .Net Sports

    .Net Sports Guest

    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
     
    .Net Sports, Aug 31, 2005
    #1
    1. Advertising

  2. .Net Sports

    John Rivers Guest

    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")
     
    John Rivers, Aug 31, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ajit
    Replies:
    1
    Views:
    3,645
    Victor Garcia Aprea [MVP]
    Apr 24, 2004
  2. Floela
    Replies:
    3
    Views:
    582
    Jon Skeet
    Jul 10, 2003
  3. Arjen
    Replies:
    1
    Views:
    7,781
    Carl Prothman [MVP]
    Aug 6, 2003
  4. Andrew
    Replies:
    0
    Views:
    671
    Andrew
    Aug 12, 2003
  5. Alan Silver
    Replies:
    5
    Views:
    2,600
    Kevin Spencer
    Feb 15, 2005
Loading...

Share This Page