读书人

关于存储过程分页的查询条件,该如何解

发布时间: 2012-02-04 15:43:09 作者: rapoo

关于存储过程分页的查询条件
下面是存储过程分页 ASP调用部分的代码,请问怎样写查询条件,这里的默认是 " ",也就是默认把所有的记录都列举出来了.
就是下面那个 CmdSp( "@condition ")= " "该怎么写?
我换了很多方式,都出错,请指点,谢谢!
<%
dim records
page=request( "page ")
if not isnumeric(page) then
page=1
end if

if page <1 then
page=1
end if



set rs=server.createobject( "adodb.recordset ")

Set CmdSP = Server.CreateObject( "ADODB.Command ")

CmdSP.ActiveConnection = connstr 'MyConStr是数据库连接字串
CmdSP.CommandText = "sp_newpage " '指定存储过程名
CmdSP.CommandType = 4 '表明这是一个存储过程
CmdSP.Prepared = true '要求将SQL命令先行编译
'返回值
CmdSp.Parameters.Append CmdSp.CreateParameter( "RETURN_VALUE ",adInteger,adParamReturnValue,4)
'入参(表名)
CmdSp.Parameters.Append CmdSp.CreateParameter( "@tb ",adVarChar,adParamInput,50)
'入参(按该列来进行分页)
CmdSp.Parameters.Append CmdSp.CreateParameter( "@col ",adVarChar,adParamInput,50)
'入参(col列的类型,0-数字类型,1-字符类型,2-日期时间类型)
CmdSp.Parameters.Append CmdSp.CreateParameter( "@coltype ",adInteger,adParamInput)
'入参(排序,0-顺序,1-倒序)
CmdSp.Parameters.Append CmdSp.CreateParameter( "@orderby ",adInteger,adParamInput)
'入参(要查询出的字段列表,*表示全部字段)
CmdSp.Parameters.Append CmdSp.CreateParameter( "@collist ",adVarChar,adParamInput,800)
'入参(每页记录数)
CmdSp.Parameters.Append CmdSp.CreateParameter( "@pagesize ",adInteger,adParamInput)
'入参(指定页)
CmdSp.Parameters.Append CmdSp.CreateParameter( "@page ",adInteger,adParamInput)
'入参(查询条件)
CmdSp.Parameters.Append CmdSp.CreateParameter( "@condition ",adVarChar,adParamInput,800)
'出参(总记录数)
CmdSp.Parameters.Append CmdSp.CreateParameter( "@RecordCount ",adInteger,adParamOutput)
'出参(总页数)
CmdSp.Parameters.Append CmdSp.CreateParameter( "@pages ",adInteger,adParamOutput)
CmdSp( "@tb ")= "title "
'上面是你的表名
CmdSp( "@col ")= "id "
'上面是表的ID
CmdSp( "@coltype ")=0
CmdSp( "@orderby ")=0
CmdSp( "@collist ")= "* "
CmdSp( "@pagesize ")=10
CmdSp( "@page ")=page
strSql= "where id> 40 "
CmdSp( "@condition ")= " "
Set rs =CmdSp.Execute



if rs.state = 0 then '未取到数据,rs关闭
recordcount = -1
else

rs.close '只有关闭才能取出返回值
recordpage=CmdSp.parameters( "@pages ")
recordcount=CmdSp.parameters( "@recordcount ")
response.write "总记页数= "&CmdSp( "@pages ")
response.write " 总记录数= "&CmdSp.parameters( "@recordcount ")
rs.open '要取出记录集,则要再打开
if int(page)> int(recordpage) then
page=recordpage
end if

%>

[解决办法]
CmdSp( "@condition ")= " "
这个是查询条件

如:
CmdSp( "@condition ")= "id> '1 ' "
这个条件自已加

读书人网 >ASP

热点推荐