Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
private void textBox5_TextChanged(object sender, EventArgs e)
{
    objConn1.Open();
    int nQty = 0;
    int nActualQty = Convert.ToInt32(textBox5.Text.ToString());
    string sql3 = "select qty from dbo.RateMouldQuantity where ratechart= '" + comboBox5.SelectedValue.ToString() + "'";
    SqlCommand com = new SqlCommand(sql3, objConn1);
    SqlDataReader objQty = com.ExecuteReader();
    if (objQty.Read())
    {
        nQty = Convert.ToInt32(objQty["Qty"]);
    }
    if (nQty < nActualQty)
    {
        MessageBox.Show("Qty is greater");
    }
    objConn1.Close();
}
Posted 18-Nov-12 23:27pm
Edited 18-Nov-12 23:33pm
Andy4112.6K
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What it means is that the string in the TextBox is not a valid integer - it may contain a decimal point, or an alphabetic character.
 
Try using TryParse instead:
int nActualQty;
if (!int.TryParse(textBox5.Text, out nActualQty))
   {
   // Report problem to user - he typed wrong.
   ...
   }
 
BTW: You do not have to call ToString on Text values - they are strings already so it does nothing useful at all...
  Permalink  
Comments
vinayak chavan at 19-Nov-12 6:00am
   
thx OriginalGriff
OriginalGriff at 19-Nov-12 6:08am
   
You're welcome!
sariqkhan at 20-Nov-12 4:41am
   
+5

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

  Print Answers RSS
0 OriginalGriff 6,651
1 Sergey Alexandrovich Kryukov 6,400
2 CPallini 5,230
3 George Jonsson 3,574
4 Gihan Liyanage 2,542


Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100