Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
See more:
hello, I have this number 157838.6, and I used many data type but nothing work when I try to insert this number in some text box bound with SQL database I have this error appear
(Input string was not in a correct format.)

What I have tried:

try float,money,decimal nothing worked
Posted
Updated 23-Aug-17 2:53am
Comments
Patrice T 23-Aug-17 19:26pm    
Show some code that exhibit the problem.

Hi,

It is not very clear what might be the problem with your data. You say that you have tried float, money, and decimal but nothing works, but the value is well within the range of any of these data types, so the range is not the problem (i.e. you don't have to hit and try all the data types, float should be enough for your requirements).

The issue could be the culture of the region you belong to.
In some regions, the NumberDecimalSeparator is a ',' whereas in others it is a '.'.

What you can do is verify which one is it. For that, you can go to control panel -> Language and regions (Language on W10) -> Change date time or number formats -> Check your decimal symbol, change it if required.
For W10 Change date time or number formats -> Additional settings and you can check here.

If the format is the problem, your best bet would be validating the input from your text box before you perform any kind of operations on it.

Thanks and good luck.
 
Share this answer
 
v2
You can use float.TryParse method to parse the textbox value.Another option is to use NumericUpDown control or maskedtextbox instead of textbox.
 
Share this answer
 
v2
Comments
Patrice T 23-Aug-17 19:27pm    
Parsing a decimal to int32, are you sure ?
itsmypassion 23-Aug-17 22:59pm    
Its float.tryparse

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900