Click here to Skip to main content
15,889,627 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,
i go through a problem in which if i deleted the value of textbox first then it will show an error of :input string is not in correct format". but if the default value which is zero, updated without delete it will works but if i delete default value it will shoe an error.

C#
private void txtAddPtechDetSplPay_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtAddPtechDetDA.Text) || string.IsNullOrEmpty(txtAddPtechDetAcaAlwnc.Text) || string.IsNullOrEmpty(txtAddPtechDetTotPay.Text) || string.IsNullOrEmpty(txtAddPtechDetHRA.Text))
{
double i = Convert.ToDouble(txtAddPtechDetDA.Text) + Convert.ToDouble(txtAddPtechDetAcaAlwnc.Text) + Convert.ToDouble(txtAddPtechDetTotPay.Text) + Convert.ToDouble(txtAddPtechDetHRA.Text) +

}
}


i think when we delete the default value so this function get null for this textbox. but it will work for some textboxes properly. please help me out
Posted
Updated 5-Nov-12 18:44pm
v2

1 solution

With all you checks, you cannot guarantee valid double floating point format in all cases. So, no matter what logic you want to apply, use double.TryParse instead of Convert:
http://msdn.microsoft.com/en-us/library/system.double.aspx[^].

"Convert" is a bad word for that, this is really parsing, not "conversion"...

—SA
 
Share this answer
 
v2

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