[RESOLVED] Quick question regarding empty recordsets
hi all
I have a recordset that sometimes will pull no data due to changes made to the database tables throughout the useage of the program. My question is this, what is the syntax to handle recordsets when they come up with no info?
i have tried things like this:
VB Code:
If rs("")<>"" then do something
and
VB Code:
IF isNull(rs("")) then do something
how would i word the part concerning the rs on order to satisfy the IF statement?
With both examples i get a
Quote:
"Item cannot be found in the collection corresponding to the requested name or ordinal."
thanks alot
tibor
Re: Quick question regarding empty recordsets
VB Code:
If rs.RecordCount = 0 Then
' No Rows Returned '
End If
Re: Quick question regarding empty recordsets
You would need a valid field name between the "".
VB Code:
If rs.Fields("FieldName").Value & "" = "" Then
' All this really tells you is that "FieldName" is Null or Blank..... '
' Record Count is One Way '
End If
VB Code:
If rs.Eof = True Then
' Also means no records (right after the select) '
End If
Re: Quick question regarding empty recordsets
ok great. thanks so much!
the Rs.EOF took care of it. The rowcount always came back as -1. Why would it ever come back as a neg?
tibor
Re: Quick question regarding empty recordsets
Quote:
Originally Posted by tibor
the Rs.EOF took care of it. The rowcount always came back as -1. Why would it ever come back as a neg?
That is a built in "featue" of an ado serverside recordset and when the CursorType is adOpenForwardonly or adOpenDynamic.
Use either adOpenKeyset or adOpenStatic as the CursorType for server side cursors or use a client side cursor. Client side cursors use only adOpenStatic for CursorTypes regardless of which CursorType you select.
Re: [RESOLVED] Quick question regarding empty recordsets
Ok, sweet. thanks. Now its something I know.. haha.
tibor
Re: [RESOLVED] Quick question regarding empty recordsets
If you set rs.CursorLocation = adUseClient (before you open the recordset) you'll get back valid rowcounts.