473,396 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

HasRows always true

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
{

Nov 17 '05 #1
2 15530
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
{

Nov 17 '05 #2
That worked great. Thank you for your help.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James Hokes | last post by:
Hi All, We're using the 1.1. Framework against SQL Server 2000, and are having a strange issue where we don't get errors back from the stored procedure, i.e. the exception never gets thrown. ...
1
by: charliewest | last post by:
Is there a .Net Compact Framework equivalent in the system.data.sqlserverce namespace of the .Net Framework system.data.sqlclient DataReader object's "Has.Rows" method? For example: ...
1
by: Claudia Fong | last post by:
Hi, I'm using the oleDbDataReader HasRows properties to detect wheter my table contains a record with the parameter below: oleDbConnection1.Close(); objreturnst.Parameters.Value =...
1
by: AJ | last post by:
I'm trying to use this property but the compiler doesn't understand HasRows and the documentation says I need 1.1 of the framework and looking in my "add or remove programs" I have the framework...
2
by: Stijn Verrept | last post by:
I am having the same problem as the person in this thread mentions: http://groups.google.be/groups?q=asp+net+empty+datareader+hasrows&hl=nl&...
2
by: TN Bella | last post by:
PLEASE HELP!! I am so far behind....and it doesn't help that I am learning all this stuff. I am using .net framework 1.0 from WebMatrix. These parameters get me all confused...someone please help!...
2
by: Jack Black | last post by:
Hi, all! What is the method for either testing for rows in a recordset or returning the number of rows in a recordset from a populated Adapter or from a DataSet? I know you can use HasRows with...
1
by: Rick | last post by:
I have found the HasRows member of the OleDbConnection. This is very nice to tell me if I have any data coming but what if I want to see how many rows of data I have. Is there a similar member to...
0
by: ashes | last post by:
Hi, i created a register form on a website. The information from the form has to go in the customer table in a database in MS Access. the information is going into the table perfectly. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.