Empty row is returned in dataset when no records is found


Having a problem with returnd data in a dataset.

if the query dosn't find any data it returns a dataset with one empty row

then i can't use :
ds.Tables(0).Rows.Count  > 0

to find if there where any returnd data

I know i can use count insted but then i have to change the code an several place..

This is what i do now

 strSQL = "SELECT TNR FROM temp WHERE TNR = '" & strTNR & "' LIMIT 1"

So Why do i get a empty row?
Who is Participating?
grayeConnect With a Mentor Commented:
I'd bet there is a problem with the MySQL provider that is messing up the "limit 1" predicate.   Try the SQL command without the "limit 1" as a test to see if that's the problem.
Jorge PaulinoIT Pro/DeveloperCommented:
Why do you use "LIMIT 1" ?
Aleksandar BradarićConnect With a Mentor Software DeveloperCommented:
This is a prime candidate for COUNT()... You already know the value of `TNR`, so you don't really need it - go with COUNT() instead, as by using `Rows.Count` you'll not be able to tell these cases apart... :(
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

AWestEngAuthor Commented:
I use LIMT one bacuse is faster then using count I just whant to check if the record exists or not. So if the record is found i don't whant mysql to check the complete table thats why I'm using LIMIT 1.

so if i cut LIMIT  then i will do the same as count.

But it seems that the code I use now dosent work.. stange

AWestEngAuthor Commented:
I think I found it.. "LIMIT 0, 1" shoud it be insted.. I will test the changes
Wayne Taylor (webtubbs)Connect With a Mentor Commented:
How about this....

        Dim strSQL As String = "SELECT TNR FROM temp WHERE TNR = '" & strTNR & "'"
        Dim cmd As New OleDbCommand(strSQL, conn)
        Dim dr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult)
        If dr.HasRows Then
        End If

AWestEngAuthor Commented:
yepp it worked just fine.. thx for all other examples :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.