7
Reply

How can I say "Code not found"?

Israel

Israel

May 7 2014 11:27 AM
779
Hi!
 
How can I receive a message saying for example:  "Code not found. Thanx!"
See what I wrote and its doenst result:
 
private void btnSearch_Click(object sender, EventArgs e)
{
string connectionString = @"Data Source=localhost\sqlexpress;Initial Catalog=master;Integrated Security=True";
SqlConnection sqlCon = new SqlConnection(connectionString);
sqlCon.Open();
string commandString = "select code, product, stocks from searching where code='" + code.Text + "'";
SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);
SqlDataReader read = sqlCmd.ExecuteReader();
while (read.Read())
{
code.Text = read["code"].ToString();
product.Text = read["product"].ToString();
Stocks.Text = read["stocks"].ToString();
}
//problem start here 
else
{
MessageBox.Show("Code not found. Thanx!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
sqlCon.Close();
}
 

Answers (7)