473,850 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ 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(T hread.CurrentTh read.CurrentCul ture,"{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(textB ox1.Text,Thread .CurrentThread. CurrentCulture) ;

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

Any ideas?

Thanks in advance.

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

int y = int.Parse(textB ox1.Text,Thread .CurrentThread. CurrentCulture) ;

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.NumberForm at );
// Same exception
i = int.Parse( "9,999", NumberStyles.In teger, Info.NumberForm at );
// This works; number style allows for grouping
i = int.Parse( "9,999", NumberStyles.Nu mber, Info.NumberForm at );

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,99 9", NumberStyles.Nu mber)
(2) But as Wessel has demonstrated it is better practice to include
CultureInfo. You can get the user's culture through
CultureInfo.Cur rentCulture:
i = int.Parse("9,99 9",
NumberStyles.Nu mber,CultureInf o.CurrentCultur e);

Also, remember to add reference to System.Globaliz ation

Cheers
Bill

Nov 17 '05 #3
Hi,

It's because the "," in the number is not understod , you have two options,
either you use InvariantCultur e 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.c om> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
Hi,
I am poulating a textbox with a number from a db, based on
the current cultrue:

textBox1.Text =
String.Format(T hread.CurrentTh read.CurrentCul ture,"{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(textB ox1.Text,Thread .CurrentThread. CurrentCulture) ;

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
768
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 error and where it originated in the code. Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 457: <tr>
1
1920
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 DataGridCommandEventArgs)
5
2519
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 not in the correct format. 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 error and where it...
1
1856
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
2862
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 = request.QueryString("enddate") Line 20: Line 21: if cint(eventid) = "0" then
0
2551
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 stack trace for more information about the error and where it originated in the code. Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 237: Dim validNow As Integer = 1 Line...
0
3171
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 consists of a label control(hidden when run in browser). Also an Sql data source control connected to database tables for a photo album. Also label web control ID=UserIdValue. Also a Details View control ID=dvPictureInsert Problem is how to work out...
1
4529
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 Photoadmin/default.aspx i got the following message and info. 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...
1
4777
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 THE PROGRAM PLEASE HELP ME Server Error in '/WebApplication1' Application. -------------------------------------------------------------------------------- Input string was not in a correct format. Description: An unhandled exception occurred...
2
2741
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 access the web site but receive an error. I am not a programmer or web developer, but if you could help that would be great. Here is the information it provides. Server Error in '/Discovery' Application....
0
9741
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11011
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10351
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9503
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7899
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7071
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4546
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.