473,325 Members | 2,785 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,325 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 19342
> 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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.