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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a specific record from recordset 1

Status
Not open for further replies.

sknyppy

Programmer
May 14, 1999
137
US
Say I have a query - 'select names from namelist'.
How can I pull the 3rd name from the query results?

Thanks,
Dave

 
Dim intLoopNbr

set intLoopNbr = 1

Do While Not RS.EOF
If intLoopNbr = 3 Then
response.write rs("names")
exit Do
end if
intLoopNbr = intLoopNbr + 1
rs.movenext
Loop
 
Thanks BarkingFrog!

Actually what I should have said was that I wanted to pull the last name in the recordset and display it. I'm still having trouble doing that.
 
This should work:

For i = 1 to rs.recordcount
If i = rs.recordcount Then
response.write rs("names")
end if
Next
 
There are also other functions you can use to do this.

Movefirst, movenext, movelast, etc......

All of these can move you through the record set after you create it. Try this link to the MSDN where they have a programmers reference for all of the ADO objects and properties. It can give you alot of insight into what you can and can't do.

The money's gone, the brain is shot.....but the liquor we still got.
 
Um, I hate posting when there are already several, but here is a built in way to do it.

objRecordset.Move 2,1

this means, move two records forward, starting at the first record. That should be the third :)

objRecordset.Move number, start
Where number is the number you would like to move and start is 1 for the the first record, 2 for the last record, and 0 for the current record

oh yeah, then get your name from objRecordset("names")

-Tarwn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top