I want to delete a record of the database.I want first to check if this record exist and if exist to proceed but if it isn't exist to diplay a message with a message box.I don't know how to set this check.Any ideas? Here is my code:
if (textBoxCode.Text != String.Empty && textBoxLastName.Text != String.Empty && textBoxFirstName.Text != String.Empty)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "delete from Student where Code='" + textBoxCode.Text + "' and Last_Name='" + textBoxLastName.Text + "' and First_Name='" + textBoxFirstName.Text + "'";
cmd.ExecuteNonQuery();
con.Close();
DisplayData();
MessageBox.Show("Student deleted successfully", "Delete Done", MessageBoxButtons.OK);
textBoxCode.Text = String.Empty;
textBoxFirstName.Text = String.Empty;
textBoxLastName.Text = String.Empty;
}