关于存储过程分页,在线等!
我调用存储过程实现分页,用ado打开数据库没问题,换成ODBC就不行了,大家帮忙看看吧
存储过程:
CREATE procedure p_splitpage
@sql nvarchar(4000), --要执行的sql语句
@currentpage int=2, --要显示的页码
@pagesize int=10, --每页的大小
@recordcount int=0 output, --记录数
@pagecount int=0 output --总页数
as
set nocount on
declare @p1 int
exec sp_cursoropen @p1 output,@sql,@scrollopt=1,@ccopt=1,@rowcount=@pagecount output
set @recordcount=@pagecount
set @pagecount=ceiling(1.0*@pagecount/@pagesize)
set @currentpage=(@currentpage-1)*@pagesize+1
--select @recordcount recordcount ,@pagecount pagecount,@currentpage currentpage
exec sp_cursorfetch @p1,16,@currentpage,@pagesize
exec sp_cursorclose @p1
set nocount off
GO
调用函数:
Function GetData(Sql,Conn,BeginNum,EndNum,R_Count,P_Count)
dim rs,Cmd
Set Cmd = Server.CreateObject( "ADODB.Command ")
Cmd.ActiveConnection=Conn
Cmd.CommandType=4 'adCmdStoredProc
Cmd.prepared=true '保存编译
Cmd.CommandText= "p_splitpage " '存储过程 名称
'设置参数
Cmd.Parameters.Append Cmd.CreateParameter( "@sql ",200,1,500,Sql)
Cmd.Parameters.Append Cmd.CreateParameter( "@currentpage ",3,1,4,BeginNum)
Cmd.Parameters.Append Cmd.CreateParameter( "@pagesize ",3,1,4,EndNum)
Cmd.Parameters.Append Cmd.CreateParameter( "@recordcount ",3,2)
Cmd.Parameters.Append Cmd.CreateParameter( "@pagecount ",3,2)
'set rs=cmd.execute '开始执行
set rs=server.CreateObject( "adodb.recordset ")
rs.CursorType =3
rs.LockType =3
rs.CursorLocation =3
set rs.Source =cmd
rs.open
R_Count=Cmd( "@recordcount ")
P_Count=Cmd( "@pagecount ")
set rs=rs.nextrecordset
set GetData=rs
End Function
调用代码:
sql= "select * from test "
Set rs = GetData(sql, Conn, currentpage, 20, r_count, p_count)
------解决方案--------------------rs.open
R_Count=Cmd( "@recordcount ")
P_Count=Cmd( "@pagecount ")
错在这里了。。。。常见问题
其实是先返回rs,然后rs.close 然后给值
R_Count=Cmd( "@recordcount ")
P_Count=Cmd( "@pagecount ")
这么个顺序就可以了