Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
5.00/5 (1 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
Updated 18-Nov-12 23:33pm
v3

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:
C#
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...
 
Share this answer
 
Comments
Master Vinu 19-Nov-12 6:00am    
thx OriginalGriff
OriginalGriff 19-Nov-12 6:08am    
You're welcome!
sariqkhan 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
Top Experts
Last 24hrsThis month


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