Traversing Backwards Through A Database (.MovePrev

Results 1 to 7 of 7

Thread: Traversing Backwards Through A Database (.MovePrev

  1. #1
    pnub Guest

    Default Traversing Backwards Through A Database (.MovePrev

    I have a guestbook which utilizes ASP and displays my guestbook with the entries from frist entry to last entry but I would like it to display them from the last entry, which would be the newest, to the first entry, which would be the oldest. I have no problem displaying them forward using .MoveNext<BR><BR>&#039this displays everything forward<BR>Do While Not objRecordset.EOF<BR> &#039display guestbook here<BR> objRecordset.MoveNext<BR>Next<BR><BR>&#039this *should* display everything backwards<BR>Do While Not objRecordset.BOF<BR> &#039display guestbook here<BR> objRecordset.MovePrev<BR>Next<BR><BR>The page times out using .MovePrev and I don&#039t know why, can anybody help me? It is probably something I am just overlooking. <BR><BR>Thanks in advance...

  2. #2
    Imar Spaanjaars Guest

    Default RE: Traversing Backwards Through A Database (.Move

    Two posibilities for you here:<BR><BR>A) Use recordSet.Movelast() first, to get to the end. The use while not BOF etc.<BR><BR>B) Better solution: use the order by something desc in your SQL statement. This orders your recordset in rversed mode, enabling you to use "while not eof" and movenext.<BR><BR>The reason for not being able to use movePrevious is that you open your recordset / connection AdForwardOnly.<BR><BR>HtH<BR><BR>Imar<BR><BR>

  3. #3
    pnub Guest

    Default RE: Traversing Backwards Through A Database (.Move

    I am doing that...look at the code that I am currently trying to use (I will Copy & Paste it):<BR><BR> objRecordset.MoveLast<BR> Do While Not objRecordset.BOF<BR> Response.Write objRecordset.Fields("id")<BR> Response.Write "&#060;B&#062;Name: &#060;/B&#062;" & objRecordset.Fields("name")<BR> Response.Write "&#060;B&#062;E-mail: &#060;/B&#062;" & objRecordset.Fields("email")<BR> Response.Write "&#060;B&#062;Website: &#060;/B&#062;" & objRecordset.Fields("website")<BR> Response.Write "&#060;B&#062;Date Entered: &#060;/B&#062;" & objRecordset.Fields("date_entered")<BR> Response.Write "&#060;B&#062;Time Entered: &#060;/B&#062;" & objRecordset.Fields("time_entered")<BR> Response.Write "&#060;B&#062;IP Address: &#060;/B&#062;" & objRecordset.Fields("ip_address")<BR> Response.Write "&#060;B&#062;Comments: &#060;/B&#062;" & objRecordset.Fields("comments")<BR> objRecordset.MovePrev<BR> Loop

  4. #4
    Imar Spaanjaars Guest

    Default RE: Traversing Backwards Through A Database (.Move

    Maybe you should use objRecordset.MovePrevious().<BR><BR>Otherwise, this code should work.<BR>Did you try the SQL-solution yet??<BR><BR>Imar<BR>


  5. #5
    pnub Guest

    Default RE: Traversing Backwards Through A Database (.Move

    I have never used SQL before so I wouldn&#039t even know where to begin...any pointers/helpers? Let me try the .MovePrevious first...although I don&#039t think that works either.

  6. #6
    Imar Spaanjaars Guest

    Default RE: Traversing Backwards Through A Database (.Move

    OK so how do you open your recordset and database??<BR>There are certain ways of opening them, based on how you want to navigate through the recordset. One of them is adOpenForwardOnly. This method (I believe it&#039s the default) allows only forward navigating through your recordset.<BR>If this is the case, a Recordset.movePrevious will generate an error. So you should check how you open your connection and recordset.<BR><BR>If you show your SQL statement that you use to get your recordset, I can try to alter it for you so it does what you want. Ans some more code around this situation might help in solving the problem.<BR><BR>Imar<BR><BR>

  7. #7
    pnub Guest

    Default RE: Traversing Backwards Through A Database (.Move

    Here is the code (Copy & Paste) that I am using. The only thing which is not listed is the SubRoutine ShowEntries:<BR><BR>&#060;!-- #INCLUDE FILE="variables.inc" --&#062;<BR>&#060;!-- #INCLUDE VIRTUAL="/include/adovbs.inc" --&#062;<BR>&#060;%<BR> Dim DB_CONNECTSTRING<BR> DB_CONNECTIONSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath(strDataBase) & ";"<BR> Set objRecordset = Server.CreateObject("ADODB.Recordset")<BR> objRecordset.Open strBook, DB_CONNECTIONSTRING, adOpenStatic, adLockPessimistic, adCmdTable<BR><BR> If boolLastEntryFirst Then<BR> objRecordset.MoveLast<BR> Do While Not objRecordset.BOF<BR> ShowEntries<BR> objRecordset.MovePrevious<BR> Loop<BR> Else<BR> objRecordset.MoveFirst<BR> Do While Not objRecordset.EOF<BR> ShowEntries<BR> objRecordset.MoveNext<BR> Loop<BR> End If<BR><BR> objRecordset.Close<BR> Set objRecordset = Nothing<BR>%&#062;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •