I want to check if the staff member does not already exists in the database before I add. In the below code, the if(dr.HasRows) statement executes even if the select statement returned no results. I don't know what I'm doing wrong. Please help.
using (SqlCommand sqlCommand = new SqlCommand("select COUNT(*) from
[CLIENT_PROCESSING_CLIENT_INFORMATION] where Client_NB_Number
= @StaffNo", sqlConn))
{
sqlCommand.Parameters.AddWithValue("@StaffNo", strStaffNumber);
SqlDataReader dr = sqlCommand.ExecuteReader();
string strMsg = "";
if(dr.HasRows)
{
strMsg = "NB" + strStaffNumber + " already exists.";
String Script = "<Script language=\"javascript\">alert('" + strMsg + " ')
</script>";
if (!Page.ClientScript.IsClientScriptBlockRegistered("OpenAlert"))
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"OpenAlert", Script);
return;
}
}