Empty row is returned in dataset when no records is found

Posted on 2007-10-13
Last Modified: 2013-11-07

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?
Question by:AWestEng
    LVL 48

    Expert Comment

    Why do you use "LIMIT 1" ?
    LVL 17

    Assisted Solution

    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... :(
    LVL 41

    Accepted Solution

    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.
    LVL 1

    Author Comment

    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

    LVL 1

    Author Comment

    I think I found it.. "LIMIT 0, 1" shoud it be insted.. I will test the changes
    LVL 46

    Assisted Solution

    by:Wayne Taylor (webtubbs)
    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

    LVL 1

    Author Comment

    yepp it worked just fine.. thx for all other examples :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    I have been using r1soft Continuous Data Protection ( for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now