Click here to Skip to main content
15,886,362 members
Articles / Database Development / SQL Server

Input string was not in a correct format.

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
14 Feb 2013CPOL 0  
Instead of Convert (bad word, in this case!), use Decimal.TryParse or Decimal.Parse. It won't improve your code much, but TryParse will help you to avoid exception (but there is nothing wrong with exceptions). More importantly, you will understand better what you are doing. You are parsing, not...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
14 Feb 2013Sergey Alexandrovich Kryukov
Whatever you do with forms, here is how you should catch and handle all exceptions in the UI thread: How do i make a loop that will stop when a scrollbar reaches the bottom[^].I may not solve your problem, but this is one of the things you need to do.—SA
Please Sign up or sign in to vote.
14 Feb 2013Jibesh
If your input is coma separated then you can split the input and process it like belowstring []totals = txttotal.Text.Split(',');foreach(string total in totals){ Decimal decimalTotal; Decimal.TryParse(total,out decimalTotal); esc.totsa(decimalTotal); }since you havent told...
Please Sign up or sign in to vote.
14 Feb 2013Mostafa Metwally 3 alternatives  
i have a ptoblem here Input string was not in a correct format.and i can't solve itc# code :- public decimal totalsalary() { decimal ms, h, b, m, k, t; ms = Convert.ToDecimal(txtmainsalary.Text); h = Convert.ToDecimal(txthwaf.Text);...

License

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


Written By
Architect
United States United States
Physics, physical and quantum optics, mathematics, computer science, control systems for manufacturing, diagnostics, testing, and research, theory of music, musical instruments… Contact me: https://www.SAKryukov.org

Comments and Discussions