Moving to a previous record
am 16.07.2006 05:00:15 von James Jones
i know how to use rs.MoveNext to get the next record in the database. Was
wanting to know how to get the previous record.
I tried rs.MovePrevious and i get error.....
My code is as follows (the database is opened, and a query is already ran
and all)
rs.MovePrevious
Previous_ID = rs.Fields("id").Value
Previous_Artist = rs.Fields("Artist").Value
Previous_Title = rs.Fields("Title").Value
rs.MoveNext
rs.MoveNext
Next_ID = rs.Fields("id").Value
Next_Artist = rs.Fields("Artist").Value
Next_Title = rs.Fields("Title").Value
I then get error:
ADODB.Recordset error '800a0c93'
Operation is not allowed in this context.
/playvideos.asp, line 132
any idea why?
thanks a lot!
James
Re: Moving to a previous record
am 16.07.2006 14:36:19 von reb01501
James Jones wrote:
> i know how to use rs.MoveNext to get the next record in the database.
> Was wanting to know how to get the previous record.
>
> I tried rs.MovePrevious and i get error.....
>
> My code is as follows (the database is opened, and a query is already
> ran and all)
>
>
>
> rs.MovePrevious
> Previous_ID = rs.Fields("id").Value
> Previous_Artist = rs.Fields("Artist").Value
> Previous_Title = rs.Fields("Title").Value
> rs.MoveNext
> rs.MoveNext
> Next_ID = rs.Fields("id").Value
> Next_Artist = rs.Fields("Artist").Value
> Next_Title = rs.Fields("Title").Value
>
>
>
>
> I then get error:
>
>
> ADODB.Recordset error '800a0c93'
> Operation is not allowed in this context.
This is probably due to the cursor type you are using when opening the
recordset. The default cursor type is a firehose cursor: forward-only.
A few thoughts for you:
It is possible to construct a sql query that returns the data in the
"previous" row in the same record as the current row. Provide some details
if you wish to explore this route.
You would probably be better off using a GetRows array:
http://www.aspfaq.com/show.asp?id=2467 but choosing a different cursor type
will allow you to move backwards in the cursor. Changing CursorLocation to
client (adUseClient) will cause ADO to use the ADO Cursor Library, forcing a
static, client-side cursor which supports full navigation to be used. See
http://msdn.microsoft.com/library/en-us/ado270/htm/mdcstcurs orlocationenum.asp
However, if you wish to use a server-side cursor, then set the CursorType
property to the cheapest cursor that supports the functionality you need. In
ADO, this is probably adOpenStatic. See:
http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthrsto pen.asp
and
http://msdn.microsoft.com/library/en-us/ado270/htm/mdcstcurs ortypeenum.asp
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"