473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Specified cast error on an integer datatype

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

Nov 19 '05 #1
1 1384
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ganesan Rajaraman | last post by:
In the following examples, why the first case statement works and why the second doesn't, I wonder. Could anyone shed some light on this? Thanks, Ganesh -- this is an attempt to: -- ...
5
by: .Net Sports | last post by:
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...
7
by: simon | last post by:
I declare variable as int16: int16 hourS; then I open dataReader and set the variable: hourS=rdr.getInt16(1); but I get an error when I start the page:
4
by: Tyro | last post by:
Can someone shed some light on my error here? Thanks! Specified cast is not valid. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Stack Trace:
3
by: PK9 | last post by:
I am looking for assistance in pinpointing the cause of the following exception. I am getting a "Specified Cast is not valid" exception on my page. I am trying to populate a datagrid. One of my...
4
by: Web Team | last post by:
Hi All, When I run the below code, I get error 'Specified cast is not valid' on line 163 Dim Address As OldInfra.BS7666.Address = BS7666AddressCollection.GetSingleAddress(str_UPRN) 164...
6
by: John-Arne Lillebų | last post by:
Hi. I run into this problem and i could need some help to solve it. The project is an ASP.NET Web project. Including code sample of the problem. Any idea what is causing the error message ?...
1
by: .Net Sports | last post by:
I have a datagrid script where I modify data in an sql dbase in asp.net, when i hit the "update" button, I get a Specified cast is not valid error on my 'descript' declaration, whereas 'descript'...
1
by: one320b | last post by:
I've read through numerous postings by other users here but was not able to find the solution to my issue. It's probably a simple one, but it's racking me at this point. I have two databases in MS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.