(
取自 Worx 英文版的<<Professional Active Server Pages 3.0>>
ISBN1861002610
关键地方我已作了中文翻译
)
CREATE PROCEDURE usp_PagedAuthors
@iPage int,
@iPageSize int
AS
BEGIN
-- disable row counts
SET NOCOUNT ON
-- declare variables
DECLARE @iStart int -- start record
DECLARE @iEnd int -- end record
DECLARE @iPageCount int -- total number of pages
-- create the temporary table
--建立临时表。
CREATE TABLE #PagedAuthors (
--这个自增字段十分关键,就是靠他来完成分页标示。
ID int IDENTITY,
au_id varchar(11) NOT NULL ,
au_lname varchar(40) NOT NULL ,
au_fname varchar(20) NOT NULL ,
phone char(12) NOT NULL ,
address varchar(40) NULL ,
city varchar(20) NULL ,
state char(2) NULL ,
zip char(5) NULL ,
contract bit NOT NULL
)
-- populate the temporary table
--先转存到上面的这个纪录集。
INSERT INTO #PagedAuthors (au_id, au_lname, au_fname,
phone, address, city, state, zip, contract)
SELECT au_id, au_lname, au_fname,
phone, address, city, state, zip, contract
FROM authors
-- work out how many pages there are in total
SELECT @iPageCount = COUNT(*)
FROM authors
' Create the table
' start building the table
Response.Write "<TABLE BORDER=1><THEAD><TR>"
For Each fldF In rsData.Fields
Response.Write "<TD>" & fldF.Name & "</TD>"
Next
Response.Write "</TR></THEAD><TBODY>"
' now loop through the records
While Not rsData.EOF
Response.Write "<TR>"
For Each fldF In rsData.Fields
Response.Write "<TD>" & fldF.Value & "</TD>"
Next
Response.Write "</TR>"
rsData.MoveNext
Wend
Response.Write "</TBODY></THEAD></TABLE><P>"
' now some paging controls
sMe = Request.ServerVariables("SCRIPT_NAME")
Response.Write " <A HREF=" & sQuote & sMe & "?PAGE=1" & sQuote & ">First Page</A>"
' close the recordset and extract the number of records left
rsData.Close
iLastPage = cmdAuthors.Parameters("RETURN_VALUE")
' only give an active previous page if there are previous pages
If iPage <= 1 Then
Response.Write " <SPAN>Previous Page</SPAN>"
Else
Response.Write " <A HREF=" & sQuote & sMe & "?PAGE=" & iPage - 1 & sQuote & ">Previous Page</A>"
End If
' only give an active next page if there are more pages
If iLas