access_asp thread: Problem with paging data from a database
Message #1 by "Shabbir Moiyed" <shabbirj82@h...> on Mon, 27 Jan 2003 09:12:19
|
|
Hi
Imagine that there are 27 records . I have done the following paging code.
now the problem is after display 5 records on every page there will totaly
5 pages . so totally on 5 pages it is diplaying 25 records . but when i
click on the 6 the page it gives me error since there only three records
on in the database and this is causing some conflict.
so please help me to what to do next
my code is as follows
<% language="vbscript" %>
<%
Server.ScriptTimeOut = 40
Session("filepath") = "../db"
Session("conn") = "provider=microsoft.jet.oledb.4.0;" &_
"data source=C:\Documents and
Settings\shabbir\Desktop\project\dating_users.mdb;" &_
"persist security info=false"
set objconn=server.createobject("adodb.connection")
strconn=session("conn")
objconn.open strconn
set objrs=server.createobject("adodb.recordset")
objrs.cursorlocation=3
'objrs.cursortype=3
objrs.pagesize=10
objrs.open "select * from members" ,objconn
Response.Write "<table><tr>"
for i=1 to objrs.PageCount
'response.write"<form action=""paging.asp"" method=""get"">"
Response.Write "<td><a href=paging.asp?pg=" & i & ">" & i & "</a></td>"
'response.write "</form>"
next
Response.Write "</tr></table><br>"
if Request.QueryString("pg")="" then
objrs.AbsolutePage=1
For i=1 to 10
Response.Write objrs.Fields("fname") & "<br>"
objrs.MoveNext
Next
else
objrs.AbsolutePage=cint(Request.QueryString("pg"))
For i=1 to 10
Response.Write objrs.Fields("fname") & "<br>"
objrs.MoveNext
Next
end if
%>
thanks
Message #2 by "Dale James Wright" <dwright@c...> on Mon, 27 Jan 2003 15:50:50
|
|
Can you clarify the question?
You say that you have 25 records..Eash display 5 records on a page....
This means you have 5 pages...Right when you click on page 5, you have
moved to the end of the recordset, which means after page 5 there is no
more records....Right so if you have set it up correct, you will only have
a move previous link/button displayed and not a move next....
You need to explain what error you are getting!
Regards
Message #3 by "Shabbir Moiyed" <shabbirj82@h...> on Mon, 27 Jan 2003 17:31:03
|
|
thanks dale for your answer
well theere are actually 27 records.. the error that i get is as follows
the code is as follows
<% language="vbscript" %>
<%
Server.ScriptTimeOut = 40
Session("filepath") = "../db"
Session("conn") = "provider=microsoft.jet.oledb.4.0;" &_
"data source=C:\Documents and
Settings\shabbir\Desktop\project\dating_users.mdb;" &_
"persist security info=false"
set objconn=server.createobject("adodb.connection")
strconn=session("conn")
objconn.open strconn
set objrs=server.createobject("adodb.recordset")
objrs.cursorlocation=3
objrs.cursortype=3
objrs.pagesize=10
objrs.open "select * from members" ,objconn
Response.Write "<table><tr>"
for i=1 to objrs.PageCount
'response.write"<form action=""paging.asp"" method=""get"">"
Response.Write "<td><a href=paging.asp?pg=" & i & ">" & i & "</a></td>"
'response.write "</form>"
next
Response.Write "</tr></table><br>"
if Request.QueryString("pg")="" then
objrs.AbsolutePage=1
For i=1 to 10
Response.Write objrs.Fields("fname") & "<br>"
objrs.MoveNext
Next
else
objrs.AbsolutePage=cint(Request.QueryString("pg"))
For i=1 to 10
Response.Write objrs.Fields("fname") & "<br>"
objrs.MoveNext
Next
end if
the error is in line 39 last for loop and the error is as follows
Error Type:
(0x80020009)
Exception occurred.
/dating/paging.asp, line 39
Please Help :<:<:<:<:<
Shabbir
> Can you clarify the question?
> You say that you have 25 records..Eash display 5 records on a page....
T> his means you have 5 pages...Right when you click on page 5, you have
m> oved to the end of the recordset, which means after page 5 there is no
m> ore records....Right so if you have set it up correct, you will only
have
a> move previous link/button displayed and not a move next....
> You need to explain what error you are getting!
> Regards
Message #4 by "Dale James Wright" <dwright@c...> on Mon, 27 Jan 2003 18:07:55
|
|
This error is generally seen when you try to concat a datafield which is
empty/null. Ensure that the database fields are not null or emtpy.... Hope
this helps....
Also you have commented some of your code out... using ' stroke.....
Ensure that you have adovbs.inc included as well......
Regards
Dale
Message #5 by "Lori Gudenkauf" <LoriLGudenkauf@u...> on Tue, 28 Jan 2003 01:12:31
|
|
Hi
You need to add this line
If objRS.EOF Then Exit For
in the 'For' 1 to objrs.PageCount section
this will solev your problem :-)
> Hi
I> magine that there are 27 records . I have done the following paging
code.
> now the problem is after display 5 records on every page there will
totaly
5> pages . so totally on 5 pages it is diplaying 25 records . but when i
c> lick on the 6 the page it gives me error since there only three records
o> n in the database and this is causing some conflict.
> so please help me to what to do next
> my code is as follows
> <% language="vbscript" %>
<> %
> Server.ScriptTimeOut = 40
> Session("filepath") = "../db"
> Session("conn") = "provider=microsoft.jet.oledb.4.0;" &_
> "data source=C:\Documents and
S> ettings\shabbir\Desktop\project\dating_users.mdb;" &_
> "persist security info=false"
> set objconn=server.createobject("adodb.connection")
s> trconn=session("conn")
o> bjconn.open strconn
s> et objrs=server.createobject("adodb.recordset")
o> bjrs.cursorlocation=3
'> objrs.cursortype=3
o> bjrs.pagesize=10
> objrs.open "select * from members" ,objconn
> Response.Write "<table><tr>"
f> or i=1 to objrs.PageCount
'> response.write"<form action=""paging.asp"" method=""get"">"
R> esponse.Write "<td><a href=paging.asp?pg=" & i & ">" & i & "</a></td>"
'> response.write "</form>"
n> ext
R> esponse.Write "</tr></table><br>"
> if Request.QueryString("pg")="" then
o> bjrs.AbsolutePage=1
> For i=1 to 10
R> esponse.Write objrs.Fields("fname") & "<br>"
o> bjrs.MoveNext
N> ext
> else
o> bjrs.AbsolutePage=cint(Request.QueryString("pg"))
> For i=1 to 10
R> esponse.Write objrs.Fields("fname") & "<br>"
o> bjrs.MoveNext
N> ext
e> nd if
> %>
> thanks
Message #6 by "Shabbir Moiyed" <shabbirj82@h...> on Tue, 28 Jan 2003 03:39:51
|
|
Yes it worked thanks..
another problem is that i wanted to know that how should i bold out the
page number that i am on
thanks
shabbir:)
> Hi
Y> ou need to add this line
> If objRS.EOF Then Exit For
i> n the 'For' 1 to objrs.PageCount section
> this will solev your problem :-)
>
>> Hi
I> > magine that there are 27 records . I have done the following paging
c> ode.
> > now the problem is after display 5 records on every page there will
t> otaly
5> > pages . so totally on 5 pages it is diplaying 25 records . but when
i
c> > lick on the 6 the page it gives me error since there only three
records
o> > n in the database and this is causing some conflict.
> > so please help me to what to do next
> > my code is as follows
> > <% language="vbscript" %>
<> > %
> > Server.ScriptTimeOut = 40
> > Session("filepath") = "../db"
> > Session("conn") = "provider=microsoft.jet.oledb.4.0;" &_
> > "data source=C:\Documents and
S> > ettings\shabbir\Desktop\project\dating_users.mdb;" &_
> > "persist security info=false"
> > set objconn=server.createobject("adodb.connection")
s> > trconn=session("conn")
o> > bjconn.open strconn
s> > et objrs=server.createobject("adodb.recordset")
o> > bjrs.cursorlocation=3
'> > objrs.cursortype=3
o> > bjrs.pagesize=10
> > objrs.open "select * from members" ,objconn
> > Response.Write "<table><tr>"
f> > or i=1 to objrs.PageCount
'> > response.write"<form action=""paging.asp"" method=""get"">"
R> > esponse.Write "<td><a href=paging.asp?pg=" & i & ">" & i & "</a></td>"
'> > response.write "</form>"
n> > ext
R> > esponse.Write "</tr></table><br>"
> > if Request.QueryString("pg")="" then
o> > bjrs.AbsolutePage=1
> > For i=1 to 10
R> > esponse.Write objrs.Fields("fname") & "<br>"
o> > bjrs.MoveNext
N> > ext
> > else
o> > bjrs.AbsolutePage=cint(Request.QueryString("pg"))
> > For i=1 to 10
R> > esponse.Write objrs.Fields("fname") & "<br>"
o> > bjrs.MoveNext
N> > ext
e> > nd if
> > %>
> > thanks
Message #7 by "Lori Gudenkauf" <LoriLGudenkauf@u...> on Thu, 30 Jan 2003 09:18:11
|
|
Hiya,
Put this near the top, like before you even open your recordset...
If Request.ServerVariables("CONTENT_LENGTH") = 0 Then
intCurrentPage = 1
Else
intCurrentPage = CInt(Request.Form("CurrentPage"))
Select Case Request.Form("Submit")
Case "First"
intCurrentPage = 1
Case "Previous"
intCurrentPage = intCurrentPage - 1
Case "Next"
intCurrentPage = intCurrentPage + 1
Case "Last"
intCurrentPage = CInt(Request.Form("TotalPages"))
End Select
End If
then this like after you open the recordset but before writing the html
page...
objRS.PageSize = intPageSize
If Not(objRS.EOF) Then objRS.AbsolutePage = intCurrentPage
intTotalPages = objRS.PageCount
Then this after the For section that writes each page...
Page <%= intCurrentPage %> of <%= intTotalPages %>
<FORM ACTION="<%= Request.ServerVariables("SCRIPT_NAME") %>" METHOD="POST">
<INPUT TYPE="Hidden" NAME="CurrentPage" VALUE="<%= intCurrentPage %>">
<INPUT TYPE="Hidden" NAME="TotalPages" VALUE="<%= intTotalPages %>">
<%
If intCurrentPage > 1 Then %>
<INPUT TYPE="Submit" NAME="Submit" VALUE="First">
<INPUT TYPE="Submit" NAME="Submit" VALUE="Previous">
<% End If
If intCurrentPage <> intTotalPages Then %>
<INPUT TYPE="Submit" NAME="submit" VALUE="Next">
<INPUT TYPE="Submit" NAME="submit" VALUE="Last">
<% End If %>
</FORM>
That should do the trick :-)
> Yes it worked thanks..
> another problem is that i wanted to know that how should i bold out the
p> age number that i am on
> thanks
> shabbir:)
>
>> Hi
Y> > ou need to add this line
> > If objRS.EOF Then Exit For
i> > n the 'For' 1 to objrs.PageCount section
> > this will solev your problem :-)
> >
>> > Hi
I> > > magine that there are 27 records . I have done the following paging
c> > ode.
> > > now the problem is after display 5 records on every page there will
t> > otaly
5> > > pages . so totally on 5 pages it is diplaying 25 records . but
when
i>
c> > > lick on the 6 the page it gives me error since there only three
r> ecords
o> > > n in the database and this is causing some conflict.
> > > so please help me to what to do next
> > > my code is as follows
> > > <% language="vbscript" %>
<> > > %
> > > Server.ScriptTimeOut = 40
> > > Session("filepath") = "../db"
> > > Session("conn") = "provider=microsoft.jet.oledb.4.0;" &_
> > > "data source=C:\Documents and
S> > > ettings\shabbir\Desktop\project\dating_users.mdb;" &_
> > > "persist security info=false"
> > > set objconn=server.createobject("adodb.connection")
s> > > trconn=session("conn")
o> > > bjconn.open strconn
s> > > et objrs=server.createobject("adodb.recordset")
o> > > bjrs.cursorlocation=3
'> > > objrs.cursortype=3
o> > > bjrs.pagesize=10
> > > objrs.open "select * from members" ,objconn
> > > Response.Write "<table><tr>"
f> > > or i=1 to objrs.PageCount
'> > > response.write"<form action=""paging.asp"" method=""get"">"
R> > > esponse.Write "<td><a href=paging.asp?pg=" & i & ">" & i
& "</a></td>"
'> > > response.write "</form>"
n> > > ext
R> > > esponse.Write "</tr></table><br>"
> > > if Request.QueryString("pg")="" then
o> > > bjrs.AbsolutePage=1
> > > For i=1 to 10
R> > > esponse.Write objrs.Fields("fname") & "<br>"
o> > > bjrs.MoveNext
N> > > ext
> > > else
o> > > bjrs.AbsolutePage=cint(Request.QueryString("pg"))
> > > For i=1 to 10
R> > > esponse.Write objrs.Fields("fname") & "<br>"
o> > > bjrs.MoveNext
N> > > ext
e> > > nd if
> > > %>
> > > thanks
|