Specified cast error on an integer datatype

Discussion in 'ASP .Net' started by .Net Sports, Jul 8, 2005.

  1. .Net Sports

    .Net Sports Guest

    I have a datagrid codebehind script that takes data from sql dbase and
    displays it in a footer row as a total. One column has amount_dollars
    (which works fine), while another has new sales (which is "newstotal"),
    but I'm getting an error (System.InvalidCastException: Specified cast
    is not valid) from the newstotal line:

    price = (Decimal)(rowData["Amount_Dollars"]);
    newstotal = (rowData["News"]);

    newstotal is an integer, just wondering what datatype i should use
    (whereas 'price' is a money datatype, and I can format it as Decimal,
    but I just want the newstotal to be a simple integer. )Using (Integer)
    or (short) in front of (rowData["News"]); give me the Specified cast
    not valid error.

    ????
    ..netsports
    .Net Sports, Jul 8, 2005
    #1
    1. Advertising

  2. Hi,
    Try to use Convert.ToInt32 to cast to integer in your case.


    ".Net Sports" wrote:

    > I have a datagrid codebehind script that takes data from sql dbase and
    > displays it in a footer row as a total. One column has amount_dollars
    > (which works fine), while another has new sales (which is "newstotal"),
    > but I'm getting an error (System.InvalidCastException: Specified cast
    > is not valid) from the newstotal line:
    >
    > price = (Decimal)(rowData["Amount_Dollars"]);
    > newstotal = (rowData["News"]);
    >
    > newstotal is an integer, just wondering what datatype i should use
    > (whereas 'price' is a money datatype, and I can format it as Decimal,
    > but I just want the newstotal to be a simple integer. )Using (Integer)
    > or (short) in front of (rowData["News"]); give me the Specified cast
    > not valid error.
    >
    > ????
    > ..netsports
    >
    >
    =?Utf-8?B?Q2hhbmRyYWt1bWFy?=, Jul 8, 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. Andrew
    Replies:
    0
    Views:
    658
    Andrew
    Aug 12, 2003
  2. Stefan Landgraf

    Re: 'Specified Cast Is Not Valid' Error!

    Stefan Landgraf, Aug 19, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    402
    Stefan Landgraf
    Aug 19, 2003
  3. Miguel Angel Dinelli
    Replies:
    1
    Views:
    442
    Chris Jackson
    Nov 13, 2003
  4. Allen
    Replies:
    10
    Views:
    764
    Sylvester Hesp
    Jan 31, 2007
  5. Jeff
    Replies:
    2
    Views:
    1,126
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Apr 16, 2007
Loading...

Share This Page