October 2nd, 2003, 12:58 AM
#1
ASP Acess Database Error: Rowset does not support fetching backward.
Hi, I'm coding a guestbook in ASP .
It is hosted at brinkster.com and I'm having an error i never had before:
Code:
Microsoft OLE DB Provider for ODBC Drivers error '80040e24'
Rowset does not support fetching backward.
/devastadorez/torpedo.asp, line 94
Here is the code:
Code:
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta HTTP-EQUIV="Cache-Control" content="no-store">
<meta HTTP-EQUIV="Pragma" content="no-cache">
<title>Torpedo</title>
<link href="style.css" type="text/css" rel="STYLESHEET">
</head>
<body bgcolor="#000000" text="#FF0000" topmargin="10" leftmargin="10">
<p><!--#include file="top.js"--></p>
<%
Const MessagesPerPage = 20
Const MaxCharsInDE = 50
Const MaxCharsInPARA = 50
Const MaxCharsInTXT = 500
Dim Err_LargeDe: Err_LargeDe = "O campo 'De' está muito longo. Encurte para no máximo " & MaxCharsInDE & " carácteres"
Dim Err_LargePara: Err_LargePara = "O campo 'Para' está muito longo. Encurte para no máximo " & MaxCharsInPARA & " carácteres"
Dim Err_LargeTxt: Err_LargeTxt = "A menssagem está muito longa. Encurte para no máximo " & MaxCharsInTXT & " carácteres"
Dim conn, rs ' Database connection and recordset
Dim strDe, strPara, strTxt ' Hold message text
Dim Offset
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("\devastadorez\db\torpedo.mdb") & ";")
strDe = Server.HTMLEncode(Trim(Request.Form("frmDe")))
strPara = Server.HTMLEncode(Trim(Request.Form("frmPara")))
strTxt = Server.HTMLEncode(Trim(Request.Form("frmTxt")))
Offset = Request.QueryString("offset")
If strDe <> "" And strPara <> "" And strTxt <> "" Then
Dim CanAdd: CanAdd = True
If Len(De) > MaxCharsInDE Then
Response.Write Err_LargeDe & "<br>"
CanAdd = False
End If
If Len(Para) > MaxCharsInPARA Then
Response.Write Err_LargePara & "<br>"
CanAdd = False
End If
If Len(Txt) > MaxCharsInTXT Then
Response.Write Err_LargeTxt & "<br>"
CanAdd = False
End If
If CanAdd Then
conn.Execute "insert into tab1 (De,Para,Menssagem,IP,Data)values ('" & strDe & "', '" & strPara & "', '" & strTxt & "', '" & Request.ServerVariables("REMOTE_ADDR") & "', '" & Now & "') "
strDe = ""
strPara = ""
strTxt = ""
End If
End If
%>
<table border="1" cellspacing="0" width="400" bordercolor="#000000" bordercolordark="#FFFFFF" bordercolorlight="#000000">
<tr><td align="center" valign="top" bgcolor="#808080"><font color="#000000" size="4">Enviar torpedo anônimo</font></td>
</tr><tr><td bgcolor="#C0C0C0">
<form method="POST" action="torpedo.asp"><center>
<font color="#000000">De <input type="text" size="20" maxlength="30" name="frmDe" class="TextBox" value="<%=strDe%>"><br>
Para <input type="text" size="20" maxlength="30" name="frmPara" class="TextBox" value="<%=strPara%>"><br>
Menssagem:</font><br><textarea name="frmTxt" rows="5" cols="50" class="TextBox"><%=strTxt%></textarea><br>
<input type="submit" name="frmEnviar" value=" Enviar! " class="TextBox">
</form>
</td>
</tr>
</table>
<%
Set rs = conn.Execute("SELECT * FROM tab1")
if not (rs.bof and rs.eof) then
%><ul><%
rs.movelast
Do
%>
<li><font color="#FFFF00">De <%=rs.Fields("De")%> Para <%=rs.Fields("Para")%></font><br>
<%=rs.Fields("Menssagem")%>
<%
rs.MovePrevious
Loop While Not rs.bof
%></ul><%
end if
set rs = nothing
conn.close
set con = nothing
%>
</body>
</html>
I do MoveLast because i need to get the newest message to diplay first. So I presume that the newest message is in the end of the table.
Why does it show this error? How can I bypass it?
Thanks for your atention...
Last edited by bubu; October 2nd, 2003 at 01:03 AM .
All consequences are eternal in some way.
October 2nd, 2003, 01:13 AM
#2
Ok ok.. Fixed the problem by doing rs.movefirst and then using rs.movenext.... But still the messages will apear from older to newer.....
Last edited by bubu; October 2nd, 2003 at 12:57 PM .
All consequences are eternal in some way.
October 2nd, 2003, 10:02 PM
#3
Hi bubu,
It is because the cursor returned from the Execute method is of type ForwardOnly by default, as name implies moving backward (MovePrevious) is not valid.. So if you want to customize the cursor, you will use the Open method of the recordset object. And probably, you would choose the cursor that supports the MovePrevious (i.e., KeySet, Dynaset, or even the Static)..
Code:
<%
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM tab1", conn, adOpenKeyset, adLockReadOnly
'OR if you didn't include the file for ADODB constants
'rs.Open "SELECT * FROM tab1", conn, 1,1
if not (rs.bof and rs.eof) then
%><ul><%
rs.movelast
Do
%>
<li><font color="#FFFF00">De <%=rs.Fields("De")%> Para <%=rs.Fields("Para")%></font><br>
<%=rs.Fields("Menssagem")%>
<%
rs.MovePrevious
Loop While Not rs.bof
%></ul><%
end if
rs.Close
set rs = nothing
conn.close
set con = nothing
%>
Busy
October 2nd, 2003, 10:06 PM
#4
If you capture the date and time of the data, you could always do an "ORDER BY", which would put your records in the order you want them to be in.
Be nice to Harley riders...
October 2nd, 2003, 11:24 PM
#5
Thanks! It's working now!
Really really thanks. Thread1, I used your suggestion and it was working, just forgot to post it here (too bad).
Twodogs, how could I order from older to newer? Because I do register the Date and the IP of the message poster. I just don't post it....
All consequences are eternal in some way.
October 3rd, 2003, 12:56 AM
#6
Assuming your date field is called "InputDate"....
Code:
Dim sSql as String
sSql = "Select * from tab1 ORDER BY InputDate DESC"
Set rs = conn.Execute(sSql)
etc etc
ps - if Descending order is not what you want, try Ascending (ASC)
EDIT: Just had a thought that perhaps your date/time data is being stored as a string....if so, you will have to convert on the fly
(SQL Server syntax)
sSql = "Select * from tab1 ORDER BY Convert(DateTime, InputDate) DESC"
Last edited by Twodogs; October 3rd, 2003 at 12:59 AM .
Be nice to Harley riders...
October 3rd, 2003, 07:03 AM
#7
Thanks alot! That really helps me!
My Date is stored as Date... So I aint having problem with it....
But I'm sure it might be helpfull to anyone here, even to me in future.
The current working code is attatched in case anybody faces the same problem. It also has a warp line function for preventing long space-less lines in guestbooks, forums, etc...
Thanks again!
Attached Files
All consequences are eternal in some way.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width