Forum Moderators: open
While Not objRec.EOF
If (objRec("ID") = ID) THEN
response.Write("Success. ID = " & objRec("ID"))
varBookmark = objRec.Bookmark
ELSE
response.Write("Fail<br>")
End If
objRec.MoveNext
Wend
Whenever I call this script and it gets to this statement, it goes to the FAIL (else) case every time. If I do a response.write(objRec("ID")) in each iteration of the while loop, the expected value comes up for each entry, and when I check the value of ID it is also the expected value, however the if statement never recognizes them as equal. Does anyone have any clue what's going on here?
An example is if I pass in the ID equal to 8, the while loop goes through all the entries 1,2,...,8,...,etc and fails every time, even when it gets to 8. Both variables are printed to the screen and read "8" but the if statement doesn't recognize them as equal.
If (CLng(objRec("ID")) = CLng(ID)) Then
If you determine that the problem is that ID is a string, then you could make it a little more efficient by doing the CLng conversion on ID prior to the loop.
Also, if that is an ADO recordset, then it is also a good idea to explicitely use the Value property:
If (CLng(objRec("ID").Value) = CLng(ID)) Then