1
CREATE procedure p_splitpage
2
@sql nvarchar(4000),
3
@page int=1,
4
@pagesize int,
5
@pageCount int=0 output,
6
@recordCount int=0 output
7
as
8
set nocount on
9
declare @p1 int
10
11
exec sp_cursoropen @p1 output,@sql,@scrollopt=1,@ccopt=1,@rowcount=@pagecount output
12
set @recordCount=@pageCount
13
select @pagecount=ceiling(1.0*@pagecount/@pagesize)
14
,@page=(@page-1)*@pagesize+1
15
exec sp_cursorfetch @p1,16,@page,@pagesize
16
exec sp_cursorclose @p1
17
GO
18
19
20
'通过存储过程调用数据库的数据
21
'sql为查询语句,m_pagesize为页面显示行,rst为记录集,totalpages为分多少页,num为多少条记录,curpage为当前页数
22
Sub SelectDB(sql,m_pageSize,rst,totalpages,num,curpage)
23
if curpage = "" then
24
curpage = Trim(Request.Form("pageno"))
25
if curpage = "" then
26
curpage = Trim(Request.QueryString("pageno"))
27
end if
28
if curpage = "" then
29
curpage = 1
30
end if
31
end if
32
33
Set cmd = Server.CreateObject("ADODB.Command")
34
cmd.ActiveConnection = conn
35
cmd.CommandType = adCmdStoredProc
36
cmd.CommandText = "p_SplitPage"
37
38
cmd.Parameters.Append cmd.CreateParameter("@sql", adVarWChar, adParamInput, 4000, sql)
39
cmd.Parameters.Append cmd.CreateParameter("@page", adInteger, adParamInput, 4, curpage)
40
cmd.Parameters.Append cmd.CreateParameter("@pageSize", adInteger, adParamInput, 4, m_pageSize)
41
cmd.Parameters.Append cmd.CreateParameter("@pageCount", adInteger, adParamOutput, 4, totalpages)
42
cmd.Parameters.Append cmd.CreateParameter("@recordCount", adInteger, adParamOutput, 4, num)
43
44
'Response.Write sql&"<br/>"
45
set rst = cmd.Execute
46
set rst = rst.NextRecordSet
47
48
totalpages = cmd.Parameters("@pageCount").value
49
num = cmd.Parameters("@recordCount").value
50
51
if totalpages = 0 then totalpages = 1
52
End Sub
53

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53
