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

Input string was not in a correct format

r
Hi,
I am poulating a textbox with a number from a db, based on
the current cultrue:

textBox1.Text =
String.Format(Thread.CurrentThread.CurrentCulture, "{0:###,###,###}",number);

Now, the number has the value: 9999, and it is shown as
9,999.
When I try to parse it:

int y = int.Parse(textBox1.Text,Thread.CurrentThread.Curre ntCulture);

It gives me the "Input string was not in a correct format".

Any ideas?

Thanks in advance.

Nov 17 '05 #1
3 19353
> 9,999.
When I try to parse it:

int y = int.Parse(textBox1.Text,Thread.CurrentThread.Curre ntCulture);

It gives me the "Input string was not in a correct format".

By default, int.Parse() uses the number style "integer", which does not
allow for grouping. Grouping is allowed by default for the number style
"number". See the following example:

CultureInfo Info = new CultureInfo("en-us");
int i;
// Exception
i = int.Parse( "9,999", Info.NumberFormat );
// Same exception
i = int.Parse( "9,999", NumberStyles.Integer, Info.NumberFormat );
// This works; number style allows for grouping
i = int.Parse( "9,999", NumberStyles.Number, Info.NumberFormat );

Greetings,
Wessel
Nov 17 '05 #2
I was just about to post when I noticed Wessel's answer. Pretty much
exactly what I was going to say except two minor things:
(1) This would also work:
i = int.Parse("9,999", NumberStyles.Number)
(2) But as Wessel has demonstrated it is better practice to include
CultureInfo. You can get the user's culture through
CultureInfo.CurrentCulture:
i = int.Parse("9,999",
NumberStyles.Number,CultureInfo.CurrentCulture);

Also, remember to add reference to System.Globalization

Cheers
Bill

Nov 17 '05 #3
Hi,

It's because the "," in the number is not understod , you have two options,
either you use InvariantCulture to display the number or you just "parse"
the number back fmro the textbox, this latter solution is what I would go
for.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"r" <ra****@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi,
I am poulating a textbox with a number from a db, based on
the current cultrue:

textBox1.Text =
String.Format(Thread.CurrentThread.CurrentCulture, "{0:###,###,###}",number);

Now, the number has the value: 9999, and it is shown as
9,999.
When I try to parse it:

int y = int.Parse(textBox1.Text,Thread.CurrentThread.Curre ntCulture);

It gives me the "Input string was not in a correct format".

Any ideas?

Thanks in advance.

Nov 17 '05 #4

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

Similar topics

0
by: lianfe_ravago | last post by:
Input string was not in a correct format. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the...
1
by: Big E | last post by:
Here is my code below. I recieve this error when I run MyCommand.SelectCommand.ExecuteNonQuery() Thanks. Big E Sub MyDataGrid_Update(ByVal Sender As Object, ByVal E As...
5
by: blackg | last post by:
Input string not in correct format -------------------------------------------------------------------------------- I am trying to view a picture from a table. I am getting this error Input string...
1
by: amitbadgi | last post by:
Welcome back amitbadgi | Logout | Faq Knowledge Discovery Keys COMPUTER PROGRAMMING, DATA MINING, STATISTICS, ARTIFICIAL INTELLIGENCE * Settings * Photos * Lists * MVPs * Forums * Blogs
1
by: amitbadgi | last post by:
I am gettign this error, while migration an app to asp.net Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 19: Dim enddate =...
0
by: hudhuhandhu | last post by:
have got an error which says Input string was not in a correct format. as follows.. Description: An unhandled exception occurred during the execution of the current web request. Please review the...
0
by: sehguh | last post by:
Hiya Folks, I am Currently using windows xp. Also using Visual Web Developer 2005 and Microsoft Sql server 2005. The main page consists of an aspx page and a master page. The page also...
1
by: sehguh | last post by:
Hello folks I have recently been studying a book called "sams teach yourself asp.net 2.0 in24 hours by scott mitchell. I have reached page 614 but when i tried to run an asp page called...
1
by: differentsri | last post by:
THIS IS AN ASP.NET 1.1 APPLICATION IAM TRYING TO UPDATE THE FIELD BUT I AM NOT ABLE TO UPDATE IT? CAN U TELL THE REASON ? IT IS GIVING THE FOLLOWING ERROR BELOW I HAVE ALSO GIVEN THE CODE OF...
2
by: Mark S | last post by:
I am installing a progam called Centennal Discovery for software and hardware inventory on our network. It has a web interface to view results with graphs and such. After installation, I try to...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.