Click here to Skip to main content
15,885,104 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
C#
private void textBox10_Click(object sender, EventArgs e)
        {
            int a = 0, b = 0, c = 0;

            if (!int.TryParse(textBox8.Text,
                                System.Globalization.NumberStyles.Integer,
                                System.Globalization.CultureInfo.CurrentUICulture,
                                out a))
            {
                MessageBox.Show("u need to enter value");
            }
            else if (!int.TryParse(textBox9.Text,
                                    System.Globalization.NumberStyles.Integer,
                                    System.Globalization.CultureInfo.CurrentUICulture,
                                    out b) || (b > a))
            {
                MessageBox.Show("u entered greater value");
            }
            else
            {
                c = a - b;
                textBox10.Text = c.ToString(
                    System.Globalization.CultureInfo.CurrentUICulture);
            }

               
        }



while inserting data..this code performing subtraction correctly, then i just retrieved "added" data from DB using search query.. now textbox8,9,10 will have fetched data from DB like 12,8,4... now if i change the value of textbox9 and textbox8 and click textbox10 it need to perform subtraction(click event for textbox10) but its not performing simply MessageBox in first if statement displaying...
why this happening
Posted
Updated 18-Jan-13 3:48am
v2
Comments
Jibesh 17-Jan-13 18:11pm    
did you set the textBox8 with proper DB value?
selva_1990 18-Jan-13 9:40am    
sorry for late response... ya i just retrieve value for all three textbox...
if am adding data in textbox8 as 10, textbox9 as 5 then automatically calculate once i click in textbox10 as 5..... now if i fetch using search all data will be in three textbox... now if i change value in textbox8 and textbox9 and click in textbox10 it showing messagebox as u need to enter value... so now i need to perform calculation after fetching data
selva_1990 18-Jan-13 12:05pm    
i got answer :)
CHill60 18-Jan-13 10:32am    
What are you actually typing into textbox8 ?
selva_1990 18-Jan-13 11:55am    
again number only i'll give to calculate

1 solution

That's not really somethign we can fix for you from here - you need to look more closely at why it's failing the first TryParse operation.

Put a breakpoint on the if statement, and look at exactly what is in the textBox8.Text with the debugger - there may be a tab or other character which is difficult to see.

It might also be worth showing the code you use to load the textbox if you can't see anything obvious with the debugger.
 
Share this answer
 
Comments
fjdiewornncalwe 18-Jan-13 11:21am    
+5.
selva_1990 18-Jan-13 12:04pm    
ya i got thanks.. i mentioned database field type as money so if i give value 22 it will take as 22.0000 bcoz of that problem... good hints to find my mistake thanks lot :)
OriginalGriff 18-Jan-13 12:22pm    
You're welcome!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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