473,466 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 19359
> 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...
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
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
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
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.