SELECT COUNT(Col) will always return one row in the result set. This is why
you see HasRow is always true.
You might want to change the SQL String to
//Check that quiz name is not a duplicate during the Create(0)task
string cmdCheckName="SELECT Quiz_Name FROM Quiz WHERE Quiz_Name
= '"+valName+"' ";
so that it'll return 0 rows if quizname is not duplicate.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
"gjtired" <jo****@boystown.org> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi, I can't figure out why my HasRows code is always true. Below is a
snippet of my code.
sqlConnection1.Open();
//Check that quiz name is not a duplicate during the Create(0)task
string cmdCheckName="SELECT Count(Quiz_Name) FROM Quiz WHERE Quiz_Name
= '"+valName+"' ";
SqlCommand cmdCheck = new SqlCommand(cmdCheckName, sqlConnection1);
SqlDataReader drCheckName =
cmdCheck.ExecuteReader(CommandBehavior.CloseConnec tion);
if (drCheckName.HasRows)
{
lblErrorName.Text = "Name already exists";
}
else
{