I have the following form:
My field Quantity should be an int but I want to implement error checking.
This is my code:
private void btn_Create_Click(object sender, EventArgs e)
{
bool exit = false;
if (String.IsNullOrEmpty(tb_Quantity.Text))
{
lbl_Error.Visible = true;
lbl_Error.Text = "Check required values !";
exit = true;
}
int Quantity = int.Parse(tb_Quantity.Text.Trim());
if (!exit)
{
MessageBox.Show("Ready to be created!");
}
}
The error that I get if my quantity is empty:
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format.
What am I doing wrong?