Subject: How to check whether recordset is null?
Posted By: sms Post Date: 4/24/2008 6:57:53 AM
I am getting problem with recordset.
After select query, what I want to do is to check whether the recordset contains data or not.

I have used code like this.

Dim count as Integer
count=recordsetvariable.RecordCount

Here I always fount count=-1.

What should I do?
Reply By: mmcdonal Reply Date: 4/25/2008 10:22:53 AM
Normally what you would do is something like:

rs.Open etc...

If rs.RecordCount <> 0 Then
   'process only if there is data in the recordset

End If

You say you are always getting RecordCount equaling -1, which means there is data in the recordset. Are there times when the code runs and throws an error because there is no data in the recordset (recordcount = 0)?

If you want to take the long way around, you could always do "SELECT Count(PKField) As PKCount FROM tblMyTable WHERE..." and then, if rs("PKCount") <> 0... then run the rest of the code.

What is the code that you are running that is causing problems with emptry recordsets?



mmcdonal

Look it up at: http://wrox.books24x7.com

Go to topic 70864

Return to index page 1