Search code examples
asp-classicvbscriptrecordset

recordset .eof throwing error when empty


I've got a simple piece of vbscript in a classic asp page which checks the database for entries, and redirects if there are any. Works well if entries exist, but throws errors if there are none. I've done this kind of thing quite a bit, but for some reason it just won't work for me right now and I can't for the life of me figure out why. Here's a snippet of my code:

query = "SELECT idcat FROM categories WHERE affID="&thisAff&";"
rs = conntemp.execute(query)
if not rs.eof then
    newCat = rs("idcat")
    response.redirect "viewCat.asp?"&newCat
end if

And again, if I give a value for thisAff that has any entries in the database this works fine, but if I give one without entries then rs.eof breaks my code. Any help would be greatly appreciated, as banging my head into my desk doesn't seem to be working.


Solution

  • You have to use set

    set rs = conntemp.execute(query)