Click here to Skip to main content
13,298,175 members (81,105 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
Updated 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 19-Nov-12 6:00am
thx OriginalGriff
OriginalGriff 19-Nov-12 6:08am
You're welcome!
sariqkhan 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171207.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2017
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