server|sqlserver| Stored Procedures | Paging one of my ASP + SQL Server paging programs: The feature of this program is to drop the current page record on the page. Good performance, and do not use stored procedures, because the code is not encapsulated, so very fragmented, to use your program, you need to read the first simple. Then pay attention to the meaning of the place you need to set yourself. Some of them can be omitted. Some of the parameter passes can also be omitted.
The code is as follows:
"' The snow in the northern part of the page (SQL Server) without stored procedures-------------------------
' There are # # in the comments #的需要用户设置
' A description of the parameter passing * in the annotation is passed by parameter.
' Define variable
Dim toption ' Query Criteria
Dim torder ' Sort string
Dim torderfield ' Sort fields Available by parameter: Order_field
Dim torderdirection ' Sort Direction can be obtained by parameter: order_direction
Dim tpagesize ' Page Size
Dim ttotalcount ' Total Record number available by parameter: T_count
Dim tpagecount ' Pages
Dim tcurpage ' current page number can be obtained by parameter: page
Dim ttablename ' Table or view name
Alias for Dim Tfieldalias ' line Number
Dim tfieldlist ' Field List for query
Dim Tpagefield ' fields for paging
Dim R_count ' Number of records checked
Set Rs=server.createobject ("Adodb.recordset") ' Recordset object
' Sort processing
Torderfield=request ("Order_field") ' Get sort field (parameter pass * *)
Torderdirection=request ("Order_dir") ' Get sort direction (parameter pass * *)
if (torderfield= "") then torderfield= "Item_code" ### set the default sort field
if (torderdirection= "") then torderdirection= "ASC" ### set the default sort direction
Torder= "ORDER BY" & Torderfield & "& torderdirection &" "' Generate sort string
' Define Parameters
Tpagesize=find_rs_count ' ### set page size
Ttablename= "View_select1" ' ### set up a table or view with a query
tfieldlist= "*" ' ### list of fields to query
Tpagefield= "Item_code" ### set a field for a primary key or unique index for paging calculations
' Page handling
Tcurpage=request ("page") ' Get current page (parameter pass * *)
Ttotalcount=request ("T_count") ' Get total number of pages (parameter pass * *)
if (tcurpage= "") then tcurpage=1
if (CInt (tcurpage) =0) then tcurpage=1
if (tpagecount= "") then Tpagecount =1
if (CInt (tpagecount) =0) then Tpagecount=1
' Constructs the query condition, according to the concrete procedure, certainly is different. But the final condition must be "where??? ”
toption= "issue_flag= ' Y" "' ### set condition
If f_c<> "" Then toption= toption & F_c ' ### set conditions
If trim (toption) = "" Then
Toption = "where 1=1" ' If there is no condition, add one by yourself.
Else
Toption= "where" & Toption
End If
' Constructs the query string, the core of this paging program, which is the record we need to download only the current page
if (tcurpage>1) then
Constr= ' select Top ' & tpagesize & ' & tfieldlist & ' from ' & Ttablename & Toption
Constr =constr & "and" & Tpagefield & "Not in (select Top" & tpagesize* (tCurPage-1) & "" & TPa Gefield & "from" & Ttablename & Toption & "" & Torder & ")" & Torder
Else
Constr= ' select Top ' & tpagesize & ' & tfieldlist & ' from ' & Ttablename & toption & ' "&A mp Torder
End If