[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

Empty row is returned in dataset when no records is found

Hi

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?
0
AWestEng
Asked:
AWestEng
3 Solutions
 
jpaulinoCommented:
Why do you use "LIMIT 1" ?
0
 
Aleksandar Bradarić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... :(
0
 
grayeCommented:
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.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

0
 
AWestEngAuthor Commented:
I think I found it.. "LIMIT 0, 1" shoud it be insted.. I will test the changes
0
 
Wayne Taylor (webtubbs)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
            'whatever
        End If

Wayne
0
 
AWestEngAuthor Commented:
yepp it worked just fine.. thx for all other examples :)
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Tackle projects and never again get stuck behind a technical roadblock.
Join Now