VB6 - Negative recordcounts

Hi Experts
I'm getting negative recordcounts with this SQL query and can't run logic based on it

It's a VB6 app connecting to a SQL server file via a connection string. ie:
cn.ConnectionString = "Provider=SQLNCLI.1;Integrated Security=SSPI;" & _
        "Persist Security Info=False;" & _
        "AttachDBFileName=c:\BPSSAMPLES3.mdf;Data Source=peter-84s5hz3wy\SQLEXPRESS"
       
    cn.Open
   
Everything runs nicely, except when i need to make a variable T/F based on the recordcount. No matter the nr of corresponding records in the table, the rs.recordcount always returns -1.  rs doesn't allow rr.nomatch or rr.movefirst either, so i'm stuck for determining match / nomatch.

 many thanks

Peter


Dim rs As ADODB.Recordset 'recordset
Set rs = New ADODB.Recordset
 
rs.Open "Select * from DIABETES where InternalID = " & currentnr, cn
                Debuglist.AddItem "Recordcount for " & currentnr & " = " & rs.RecordCount
               
               '*recordcount always comes out as -1 so the following logic never works properly
                If rs.RecordCount = 0 Then
                    DSWORK("PD_Diabetic") = False
                Else
                    DSWORK("PD_Diabetic") = True
                End If
                
                rr.Close

Open in new window

peterdarazsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

carlsiyCommented:
are you sure you can connect to the database?
pls go to http://www.connectionstrings.com for the correct connection string.
 
0
peterdarazsAuthor Commented:
It certainly does connect and i'm able to populate alll my access tables correctly (except when the logic requires the recordcount.) If you don't mind, i'm going to allow this question to linger a little and see what else comes up by way of answers. many thanks
0
Ryan ChongCommented:
try set the CursorLocation to adUseClient

...

Set rs = New ADODB.Recordset

rs.CursorLocation = adUseClient
...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
carlsiyCommented:
ryancys's answer could be it. CursorLocation determines whether your returning data or not, you should set the CursorLocation to adusec.lient
0
peterdarazsAuthor Commented:
Thanks Guys - This certainly looks like the answer.

Peter
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

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.