473,385 Members | 1,693 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,385 software developers and data experts.

Input string was not in a correct format. on string "0"

Hi,

i'm reading in a bigint value from SQL Server.

string s = myReader["BackColour"].ToString());

int intBackColour = System.Convert.ToInt32(s);

I'm also reading in other values the same way and it works great
except this one value, i'm getting
System.FormatException: Input string was not in a correct format.

I don't understand because when I print out the string s to the screen
it shows 0.

Does anyone have a idea why its doing this?

Any help would be greatly appreciated.
-dp
Nov 18 '05 #1
2 2341
On 7 Jul 2004 14:17:21 -0700, oa*****@hotmail.com (chongo) wrote:
Hi,

i'm reading in a bigint value from SQL Server.

string s = myReader["BackColour"].ToString());

int intBackColour = System.Convert.ToInt32(s);

I'm also reading in other values the same way and it works great
except this one value, i'm getting
System.FormatException: Input string was not in a correct format.

I don't understand because when I print out the string s to the screen
it shows 0.

Does anyone have a idea why its doing this?

Any help would be greatly appreciated.
-dp


Very strange.

Try

int intBackColour = int.Parse(s);

instead of

int intBackColour = System.Convert.ToInt32(s);

-Adam
Nov 18 '05 #2
Yes, remember to use Convert.ToInt32 carefully, sometimes it doesn't work to
String convert , while Int32.Parse is ok.

I guess, if two types are convertable, such as Int to BigInt, or Object
to Int, System.Convert.Toxxx can work. String to Int is not
convertable, so Convert.Toxxx may be wrong sometime.

you can check MSDN for the types relation. That will give you details.
On 7 Jul 2004 14:17:21 -0700, oa*****@hotmail.com (chongo) wrote:
Hi,

i'm reading in a bigint value from SQL Server.

string s = myReader["BackColour"].ToString());

int intBackColour = System.Convert.ToInt32(s);

I'm also reading in other values the same way and it works great
except this one value, i'm getting
System.FormatException: Input string was not in a correct format.

I don't understand because when I print out the string s to the screen
it shows 0.

Does anyone have a idea why its doing this?

Any help would be greatly appreciated.
-dp


Very strange.

Try

int intBackColour = int.Parse(s);

instead of

int intBackColour = System.Convert.ToInt32(s);

-Adam

Nov 18 '05 #3

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

Similar topics

0
by: Punisher | last post by:
Ok I'm trying to reference a specific node in a tree. TreeNode nodeParentChannel = treeview1.Nodes; It bugs out with this error: Input string was not in a correct format Obviously 1.2 is not...
1
by: The Crow | last post by:
if the reason for error is simple, excuse me. but i cant find what the reason is. Here is the snippet : string script = String.Format(@"<script src='common.js'...
0
by: phmyhn | last post by:
I have two web pages, one is viewlarger.aspx, another one is shoppingcart.aspx. On the viewlarger.aspx, when clicking "add to cart" image button, the sub appends the id (passed from another page...
1
by: John Chorlton | last post by:
I've been attempting to pass a chunk of data back from a child Windows form using public properties on the form and have been getting some odd errors. I wanted to return a row of data to avoid...
3
by: dan | last post by:
I am using VB.NET 2003 and SQL Server 2000. The program uses ADO.NET . The following instruction: Me.cd_insertDataRecord.ExecuteNonQuery() throws this exception: ">>>ProcessDataRecord/...
3
by: Pieter Coucke | last post by:
Hi, When a user types a non numeric-value in a numeric column in a DataGridView, and he tries to leave the cell, he gets this "Input string was not in a correct format."-exception. Is there a...
0
by: bnlockwood | last post by:
G'day all, Thank you in advance for anyone that can help. I have a shopping cart datagrid on my c# asp.net page. This is the code: ------------------------------------- <asp:datagrid...
13
by: Jen | last post by:
One user of my application is experiencing an exception "input string not in correct format". But it makes no sense where it is occurring. It is occurring when a string from a textbox ("172") is...
9
muaddubby
by: muaddubby | last post by:
Hi I'm running into a scenario with a DataSet that has a schema loaded into it, tries to then load data (that matches the schema), and fails with a "Input string was not in a correct format"...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.