|
 |
access_asp thread: Paging with Command Object
Message #1 by mail@c... on Fri, 8 Mar 2002 15:12:24
|
|
I am trying to do paging using the Command object that goes into a
recordset, I have tried all different methods and I have not got one to
work properly yet...
This is the one that I tried with paging
<% Option Explicit
Dim strConnect
%>
<!-- #Include File = "../Connections/Datastore.asp"-->
<!-- MetaData Type = "TypeLib" File="C:\Program Files\Common
Files\System\ado\msado15.dll"-->
<html>
<head>
<title>Using the Find method to find a Director's
Films</title>
</head>
<link rel="stylesheet" href="starstyle.css" type="text/css">
<body>
<%
Dim objCommand, objRS
Dim iPage, intPage, intLastPage, strQuote
Set objCommand = Server.CreateObject
("ADODB.Command")
objCommand.ActiveConnection = strConnect
objCommand.CommandText = "SELECT * FROM AllData "
&_
"WHERE Person LIKE '%" & Request.Form
("Celeb") & "%' "
objCommand.CommandType = adCmdText
objCommand.Parameters.Append
objCommand.CreateParameter("RETURN_VALUE", adInteger, adParamReturnValue)
objCommand.Parameters.Append
objCommand.CreateParameter("@iPage", adInteger, adParamInput, 8, iPage)
objCommand.Parameters.Append
objCommand.CreateParameter("iPageSize", adInteger, adParamInput, 8, 10)
Set objRS = objCommand.Execute
If objRS.EOF Then
Response.write "That is not available"
Else
Response.write "<table border=1>"
Response.write "<tr><td>ID
Number</td><td>Celebrity</td><td>Occasion</td>" & "<td>Play
Message</td></tr>"
While Not objRS.EOF
Response.write "<tr><td>" & objRS
("ID") & "</td><td>" & objRS("Person") & "</td><td>" & objRS("Occasion")
& "</td><td>Listen</td></tr>"
objRS.MoveNext
Wend
End If
' Now some paging controls
strScriptName = Request.ServerVariables
("SCRIPT_NAME")
Response.write " <a href=" & strQuote &
strScriptName & _
"?PAGE=1" &
strQuote & ">First Page</a>"
' Only give an active previous page if there is a
previous page
If intPage <= 1 Then
Response.write " <span>Previous
Page</span>"
Else
Response.write " <a href=" & strQuote
& strScriptName & _
"?PAGE=" &
intPage -1 & strQuote & ">Previous Page</a>"
End If
' Close the recordset and extract the number of
records left
objRS.Close
intLastPage = objCommand.Parameters("RETURN_VALUE")
' Only give an active next page if there is a next
page
If intLastPage = intPage Then
Response.write " <span>Next
Page</span>"
Else
Response.write " <a href=" & strQuote
& strScriptName & _
"?PAGE=" &
intLastPage & strQuote & ">Next Page</a>"
End If
Response.write " <a href=" & strQuote &
strScriptName & _
"?PAGE=" &
intLastPage & strQuote & ">Last Page</a>"
Set objCommand = Nothing
Set objRS = Nothing
It brings up errors but the same thing without the paging part works (see
below)
<% Option Explicit
Dim strConnect
%>
<!-- #Include File = "../Connections/Datastore.asp"-->
<!-- MetaData Type = "TypeLib" File="C:\Program Files\Common
Files\System\ado\msado15.dll"-->
<html>
<head>
<title>Using the Find method to find a Director's
Films</title>
</head>
<link rel="stylesheet" href="starstyle.css" type="text/css">
<body>
<%
Dim objCommand, objRS
Set objCommand = Server.CreateObject
("ADODB.Command")
objCommand.ActiveConnection = strConnect
objCommand.CommandText = "SELECT * FROM AllData "
&_
"WHERE Person LIKE '%" & Request.Form
("Celeb") & "%' "
objCommand.CommandType = adCmdText
Set objRS = objCommand.Execute
Set objCommand = Nothing
If objRS.EOF Then
Response.write "That is not available"
Else
Response.write "<table border=1>"
Response.write "<tr><td>ID
Number</td><td>Celebrity</td><td>Occasion</td>" & "<td>Play
Message</td></tr>"
While Not objRS.EOF
Response.write "<tr><td>" & objRS
("ID") & "</td><td>" & objRS("Person") & "</td><td>" & objRS("Occasion")
& "</td><td>Listen</td></tr>"
objRS.MoveNext
Wend
End If
Set objRS = Nothing
%>
</table>
</body>
</html>
Could you please help me with this problem
Thanks
Message #2 by "Ken Schaefer" <ken@a...> on Mon, 11 Mar 2002 10:46:48 +1100
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <mail@c...>
Subject: [access_asp] Paging with Command Object
: I am trying to do paging using the Command object that goes into a
: recordset, I have tried all different methods and I have not got one to
: work properly yet...
...
:
: It brings up errors but the same thing without the paging part works (see
: below)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please post the errors you are getting.
Alternatively, you can review the code here:
www.adopenstatic.com/experiements/recordsetpaging.asp
which shows two different ways to use command objects (and sprocs, but you
could use inline SQL) to perform paging.
Cheers
Ken
|
|
 |