Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
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

Rate this: bad
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...
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 8,478
1 OriginalGriff 6,516
2 Peter Leow 3,587
3 Zoltán Zörgő 3,406
4 Richard MacCutchan 2,397

Advertise | Privacy | Mobile
Web01 | 2.8.150123.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