March 29, 2005 at 2:59 pm
Hi There, I really need help figuring out how to find a row in a recordset based on criteria. I am making previous and next buttons for a photo gallery and I can't figure out how to find a row in a recordset, move to it, check for EOF or BOF, then move previous, or next and get the value of PhotoID
I have a table of images, with these fields
PhotoID
FolderID
Filename
Description.
Isn't there a recordset.FindFirst command that will move the cursor to the desired row? How do you move the cursor around rows in an ASP recordset?
HELP!
Thanks in advance for any advice.
MySQL = "SELECT tblPhoto.PhotoID, tblPhoto.FolderID, tblPhoto.Filename FROM tblPhoto WHERE (((tblPhoto.FolderID)=" & FolderID & ")) ORDER BY tblPhoto.PhotoID;"
cmdDC.CommandText = MySQL
Set RS = Server.CreateObject("ADODB.Recordset")
rs.Open cmdDC, , 0, 2
rs.FindFirst
rs.MoveNext
GetNextPhoto = rs.Fields("PhotoID")
March 29, 2005 at 7:51 pm
ADO Recordsets have Move, MoveFirst, MoveNext, MoveLast and MovePrevious. They also have EOF and BOF properties. You also might find the AbsolutePosition property helpful. When the recordset is opened, it will already be on the first record. You will probably want to pass in the AbsolutePosition in a hidden field to the next and back requests.
If not rs.eof then
'code for next button
nextID = rs.AbsolutePosition + 1
end if
If not rs.bof then
lastID = rs.AbsolutePosition -1
end if
Aunt Kathi Data Platform MVP
Author of Expert T-SQL Window Functions
Simple-Talk Editor
March 30, 2005 at 10:28 am
Here is a little more information on working with recordsets:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdobjodbrec.asp
March 30, 2005 at 10:40 am
Thank you Ghost and Kathi, you have been a huge help!
I already wrote code to find the appropriate row, but it is not as efficient as it could be. I will rework it with these new things you have taught me.
Thanks again!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply