Click here to Skip to main content
11,496,146 members (403 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: C#
private void textBox5_TextChanged(object sender, EventArgs e)
    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");
Posted 19-Nov-12 0:27am
Edited 19-Nov-12 0:33am

1 solution

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...
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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2015
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