Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to stop state no record return on Recordset

Status
Not open for further replies.

Mike2020

Programmer
Mar 18, 2002
55
0
0
US
Hi:

when my recordset return no record. it give error message.
So I do this
Set oRSet = Server.CreateObject("ADODB.Recordset")
oRSet.CursorType = adOpenDynamic
oRSet.Open str_query,oConn
If (oRSet.RecordCount <> 0) Then
you have something here.
else
No record found
End if

But it still doesn't work. Please help.!!!

Many thanks.......
 
try this...
Code:
Set oRSet = Server.CreateObject(&quot;ADODB.Recordset&quot;)
oRSet.CursorType = adOpenDynamic
oRSet.Open str_query,oConn

If NOT oRSet.EOF Then
  you have something here.
Else
  No record found
End if
Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
try ratehr using the .EOF OR .BOF instead of the count
if not oRSet.EOF and oRSet.BOF then ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

 
Ah.. got here first [smile] ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

 
Something else that I use (and have had more luck with) is the following:

if not rs is nothing then
'whatever you would do with the returned records
else
You have no records that were returned.

HTH Insanity is merely a state of mind while crazy people have a mind of their own.
 
I'd recommend using a SELECT COUNT statement on the table of the database to see if it returns 0 or >0.
 
This would actually cause more of a performance hit because if the recordset has any data in it, then you are doing a double select, which means at least two calls to the database(depending on how you write your statements) and two recordset objects in memory(unless you reuse the first object to get the query results from the second query and remember to set it to nothing first).
If the recordset is returned empty the recordset pointer is returned pointing to both EOF and BOF. In fact if there is even one record in the recordset it will not be returned pointing to EOF, so an EOF check is a perfectly valid means to check for contents in the RecordSet.
-Tarwn Experts are only people who have realized how much they will never know about a language.
________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top