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 474
1 Gihan Liyanage 338
2 ChauhanAjay 180
3 Sergey Alexandrovich Kryukov 163
4 Vinay Mistry 160
0 Sergey Alexandrovich Kryukov 9,011
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.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