You have to use set
set rs = conntemp.execute(query)
質問
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.
解決
You have to use set
set rs = conntemp.execute(query)
他のヒント
Use rs.bof
to check if the rs is empty, as in:
'if records were returned...
If Not .BOF Then
.MoveFirst
'loop through each record
Do Until .EOF
'PUT YOUR CODE HERE
.MoveNext
Loop
End If