| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 949 人关注过本帖
标题:asp 怎么分页?我这个分页代码为什么sql语句不能带参数
只看楼主 加入收藏
withinsky
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-2-10
收藏
 问题点数:0 回复次数:5 
asp 怎么分页?我这个分页代码为什么sql语句不能带参数

搞了两天没搞定的问题:
从manage_xmzch.asp上传到search_xmzch.asp页上4个变量,分别是kaishishijian/jieshushijian/kaishichanpin/jieshuchanpin.
search_xmzch.asp接收到4个变量后,查询,并分页显示。现在的问题是,如果sql语句不带参数查询则正常分页显示,但如果带了参数,即 where 销售日期>=#"&kaishishijian&"# and 销售日期 <=#"&jieshushijian&"# and 产品编码>='"&kaishichanpin&"' and 产品编码<='"&jieshuchanpin&"' 这一句,则只能显示第一页,第二页等就显示不出来了。提示为:日期的语法错误 在查询表达式 '销售日期>=## and 销售日期 <=## and 产品编码>='' and 产品编码<=''' 中。
/sims/search_xmzch.asp, 第 57 行
可以看到这几个参数没有接收到传递的数据(第一页显示是正常的)

我把search_xmzch.asp的代码贴到这里,跪求高人指点解决:

<!--#include file="Connections/connsims.asp" -->
<!--#include file="inc/eshopcode.asp"-->
<%
if session("user")="" or session("purview")>"1" then
response.write "<script language='javascript'>window.confirm('你无此权限,请返回!')</script>"
response.write "<script language='javascript'>parent.window.history.go(-1);</script>"
response.end
end if
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
<!--
body {
margin-top: 5px;
}
-->
</style><title>按产品明细查询结果</title>
<link href="css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.STYLE2 {color: #FFFFFF}
.STYLE3 {color: #FFffff}
-->
</style>
</head>

<body>
<table width="770" height="260" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="46" height="60"><img src="images/bg_r1_c1.jpg" width="46" height="60" /></td>
<td width="676" background="images/bg_r1_c2.jpg"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="45%">&nbsp;&nbsp;</td>
<td width="55%"><div align="right"><%=session("user")%>
<!--#include file="time.js"-->
</div></td>
</tr>
</table></td>
<td width="48"><img src="images/bg_r1_c3.jpg" width="28" height="60" /></td>
</tr>
<tr>
<td height="153" background="images/bg_r2_c1.jpg">&nbsp;</td>
<td bgcolor="#FFFFFF"><!--#include file="head/head_xmz.asp" -->
<br>
<table width="712" border="1" cellpadding="5" cellspacing="0" bordercolorlight="#dddddd" bordercolordark="#FFFFFF">
<%

'if kaishishijian="" or jieshushijian="" or kaishichanpin="" or jieshuchanpin="" then
' response.redirect "manage_xmzch.asp"
'end if
set rs=server.createobject("adodb.recordset")
sql="select 销售日期,产品编码,产品名称,产品规格,sum(销售数量) as 数量,round(sum(销售件数),2) as 件数,round(sum(销售金额),2) as 金额 from V_XSRBall where 销售日期>=#"&kaishishijian&"# and 销售日期 <=#"&jieshushijian&"# and 产品编码>='"&kaishichanpin&"' and 产品编码<='"&jieshuchanpin&"' group by 销售日期,产品编码,产品名称,产品规格 order by 销售日期 desc"
'where 销售日期>=#"&kaishishijian&"# and 销售日期 <=#"&jieshushijian&"# and 产品编码>='"&kaishichanpin&"' and 产品编码<='"&jieshuchanpin&"'
rs.open sql,conn,1,1
dim PerPage
PerPage=20
'假如没有数据时
If rs.eof and rs.bof then
response.write "<p align='center'><font color='#ff0000'>还没任何内容</font></p>"
response.end
End if
'取得页数,并判断用户输入的是否数字类型的数据,如不是将以第一页显示
text="0123456789"
Rs.PageSize=PerPage
for i=1 to len(request("page"))
checkpage=instr(1,text,mid(request("page"),i,1))
if checkpage=0 then
exit for
end if
next

If checkpage<>0 then
If NOT IsEmpty(request("page")) Then
CurrentPage=Cint(request("page"))
If CurrentPage < 1 Then CurrentPage = 1
If CurrentPage > Rs.PageCount Then CurrentPage = Rs.PageCount
Else
CurrentPage= 1
End If
If not Rs.eof Then Rs.AbsolutePage = CurrentPage end if
Else
CurrentPage=1
End if

call list

If Rs.recordcount > PerPage then
end if

'显示帖子的子程序
Sub list()%>
<tr>
<td colspan="7"><div align="center">按产品明细查询结果</div></td>
</tr>
<tr>
<td width="97" bgcolor="#efefef"><div align="center">销售日期</div></td>
<td width="82" bgcolor="#efefef"><div align="center">产品编码</div></td>
<td width="93" bgcolor="#efefef"><div align="center">产品名称</div></td>
<td width="90" bgcolor="#efefef"><div align="center">产品规格</div></td>
<td width="84" bgcolor="#efefef"><div align="center">销售数量</div></td>
<td width="87" bgcolor="#efefef"><div align="center">销售件数</div></td>
<td width="93" bgcolor="#efefef"><div align="center">销售金额</div></td>
</tr>
<%
if not rs.eof then
do while not rs.eof
%>
<tr>
<td><div align="center"><%=rs("销售日期")%></div></td>
<td><div align="center"><%=rs("产品编码")%></div></td>
<td><div align="center"><%=rs("产品名称")%></div></td>
<td><div align="center"><%=rs("产品规格")%></div></td>
<td><div align="center"><%=rs("数量")%></div></td>
<td><div align="center"><%=rs("件数")%></div></td>
<td><div align="center"><%=rs("金额")%></div></td>
</tr>

<%
i=i+1
if i-1 > Perpage then exit do
rs.movenext
loop
end if
%>
</table>
<table width="664" border="1" cellpadding="5" cellspacing="0" bordercolorlight="#dddddd" bordercolordark="#FFFFFF">
<tr>
<td bgcolor="#eeeeee">&nbsp;<strong>分页浏览</strong>
<%
Response.write "<strong><font color='#000000'> -> 全部-</font>"
Response.write "共</font>" & "<font color=#FF0000>" & Cstr(Rs.RecordCount) & "</font>" & "<font color='#000000'>条记录</font></strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
Response.write "<strong><font color='#000000'>第</font>" & "<font color=#FF0000>" & Cstr(CurrentPage) & "</font>" & "<font color='#000000'>/" & Cstr(rs.pagecount) & "</font></strong>&nbsp;"
If currentpage > 1 Then
response.write "<strong><a href='search_xmzch.asp?&page="+cstr(1)+"'><font color='#000000'>首页</font></a><font color='#ffffff'> </font></strong>"
Response.write "<strong><a href='search_xmzch.asp?page="+Cstr(currentpage-1)+"'><font color='#000000'>上一页</font></a><font color='#ffffff'> </font></strong>"
Else
Response.write "<strong><font color='#000000'>上一页 </font></strong>"
End if
If currentpage < Rs.PageCount Then
Response.write "<strong><a href='search_xmzch.asp?page="+Cstr(currentPage+1)+"'><font color='#000000'>下一页</font></a><font color='#ffffff'> </font>"
Response.write "<a href='search_xmzch.asp?page="+Cstr(Rs.PageCount)+"'><font color='#000000'>尾页</font></a></strong>&nbsp;&nbsp;"
Else
Response.write ""
Response.write "<strong><font color='#000000'>下一页</font></strong>&nbsp;&nbsp;"
End if
%>
<input type='text' name='page' size=4 maxlength=4 class=text4 value="<%=Currentpage%>">
&nbsp;
<input class=submit2 type='submit' value='Go' name='cndok'>
&nbsp;&nbsp; </td>
</tr>
</table>

<table width="664" cellpadding="5">
<tr>
<td colspan="5"><div align="center">【<a href='javascript:history.back()'>返回</a>】</div></td>
</tr>
</table>
<br />
<table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td></td>
</tr>
</table></td>
<td background="images/bg_r2_c3.jpg">&nbsp;</td>
</tr>
<tr>
<td height="47"><img src="images/bg_r3_c1.jpg" width="46" height="47" /></td>
<td background="images/bg_r3_c2.jpg">&nbsp;</td>
<td><img src="images/bg_r3_c3.jpg" width="28" height="47" /></td>
</tr>
</table>
<%
End sub
rs.close
%>
</body>
</html>


搜索更多相关主题的帖子: 能带 sql 语句 参数 asp 
2006-08-30 09:44
hangxj
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2045
专家分:0
注 册:2006-4-10
收藏
得分:0 
老问题,你在首页,前一页,下一页,最后一页这些地方的链接没有把你要查询的参数传下去

http://www./
2006-08-30 10:05
withinsky
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-2-10
收藏
得分:0 
可是我加了参数以后,只能显示第一页,点击下一页还是显示第一页的内容,我想应该是给了参数以后,search_xmzch.asp再调用自身,又重新查询了一次,所以不论你怎么点,总是显示第一页的内容。我加的参数如下:版主看看有问题没有:

这里我只写页连接处的代码
原来是:
If currentpage &lt; Rs.PageCount Then
Response.write "&lt;strong&gt;&lt;a href='search_xmzch.asp?page="+Cstr(currentPage+1)+"'&gt;&lt;font color='#000000'&gt;下一页&lt;/font&gt;&lt;/a&gt;&lt;font color='#ffffff'&gt; &lt;/font&gt;"
Response.write "&lt;a href='search_xmzch.asp?page="+Cstr(Rs.PageCount)+"'&gt;&lt;font color='#000000'&gt;尾页&lt;/font&gt;&lt;/a&gt;&lt;/strong&gt;&amp;nbsp;&amp;nbsp;"
我改成:
If currentpage &lt; Rs.PageCount Then
Response.write "&lt;strong&gt;&lt;a href='search_xmzch.asp?page="+Cstr(currentPage+1)+"&amp;kaishishijian="+kaishishijian+" &amp;jieshushijian="+jieshushijian+" &amp;kaishichanpin="+kaishichanpin+"  &amp;jieshuchanpin="+jieshuchanpin+" '&gt;&lt;font color='#000000'&gt;下一页&lt;/font&gt;&lt;/a&gt;&lt;font color='#ffffff'&gt; &lt;/font&gt;"
Response.write "&lt;a href='search_xmzch.asp?page="+Cstr(Rs.PageCount)+"'&gt;&lt;font color='#000000'&gt;尾页&lt;/font&gt;&lt;/a&gt;&lt;/strong&gt;&amp;nbsp;&amp;nbsp;"
即,我在“下一页”连接总增加了&amp;kaishishijian="+kaishishijian+" &amp;jieshushijian="+jieshushijian+" &amp;kaishichanpin="+kaishichanpin+"  &amp;jieshuchanpin="+jieshuchanpin+"
参数传递了,数据也能查询出来。可惜还是只能显示第一页,点下一页的时候,还是显示第一页。好像是重新查了一次。

2006-08-30 10:36
渚薰
Rank: 6Rank: 6
等 级:贵宾
威 望:22
帖 子:1132
专家分:0
注 册:2006-8-6
收藏
得分:0 
你的数据库里是不是只够显示一页啊

个人ajax技术专题站: " target="_blank">http://www. 我不会闲你烦,只会闲你不够烦!
2006-08-30 14:51
withinsky
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-2-10
收藏
得分:0 
不是的,数据库的测试数据完全可以显示2页。
带参数的查询分页很难么?能不能提供一个做好的例子,待变量参数的sql查询结果分页。
其实,在我做的这个查询中部带参数,即不要where.........的话显示结果为12页,挺正常的。奇怪死了,我快疯了。
2006-08-30 17:34
zlily
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-8-1
收藏
得分:0 
给你一段我用的代码,挺好用的!
&lt;!--#include file="../conn/conn.asp"--&gt;

&lt;%
  oastaff_name=session("oastaff_name")
  oausername=session("oausername")
  oauserdept=session("oauserdept")
  oauserlevel=session("oauserlevel")
if oausername="" then
    response.write("&lt;script language=""javascript""&gt;")
    response.write("window.top.location.href='../default.asp';")
    response.write("&lt;/script&gt;")
    response.end
end if
%&gt;

&lt;html&gt;
&lt;title&gt;公告浏览&lt;/title&gt;
&lt;head&gt;
&lt;script language="javascript"&gt;
function openwin(href)
{
    window.open(href,'answerwin','location=no,height=450, width=640, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');
}
&lt;/script&gt;
&lt;%
  const maxperpage=7
  dim sqlstr,rs,totleput,currentpage,totlepages,i,j
%&gt;
&lt;/head&gt;
&lt;body bgcolor=thistle&gt;
&lt;p align="center"&gt;&lt;font face="宋体" size="5"&gt;&lt;strong&gt;通告信息浏览&lt;/strong&gt;
&lt;%
  sqlstr="select * from notice_inf order by notice_date desc"
  rs.open sqlstr,conn,1,1
if rs.recordcount&lt;&gt;0 then
  rs.movefirst
  rs.pagesize=maxperpage
  howmanyfields=rs.fields.count-1
  if trim(request("page"))&lt;&gt;"" then
    currentpage=clng(request("page"))
    if currentpage&gt;rs.pagecount then
      currentpage=rs.pagecount
    end if
  else
    currentpage=1
  end if
  if rs.eof then
    response.write "&lt;p align='center'&gt;ERROR!&lt;/p&gt;"
  else
    totleput=rs.recordcount
    if currentpage&lt;&gt;1 then
      if(currentpage-1)*maxperpage&lt;totleput then
        rs.move (currentpage-1)*maxperpage
        dim bookmark
        bookmark=rs.bookmark
      end if
    end if
    dim n,k
    if(totleput mod maxperpage)=0 then
      n=totleput\maxperpage
    else
      n=totleput\maxperpage+1
    end if
%&gt;

&lt;/font&gt;&lt;/p&gt;
&lt;%'if session("rs").recordcount&lt;&gt;0 then%&gt;
&lt;form method="post" name="form1" action="noticelook.asp"&gt;
&lt;table border="1" align="center"&gt;
  
  
  &lt;tr&gt;
    &lt;td width="5%"&gt;&lt;font face="黑体"&gt;编号&lt;/font&gt;&lt;/td&gt;
    &lt;td width="55%"&gt;&lt;font face="黑体"&gt;标题&lt;/font&gt;&lt;/td&gt;
    &lt;td width="40%"&gt;&lt;font face="黑体"&gt;时间&lt;/font&gt;&lt;/td&gt;
  &lt;%
   
    i=0
    do while not rs.eof and i&lt;maxperpage%&gt;
  &lt;/tr&gt;
  &lt;tr align="center"&gt;
    &lt;td&gt;&amp;nbsp;&lt;%=rs(0)%&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&lt;a href="javascript:openwin('noticeprint.asp?notice_num=&lt;%=rs("notice_num")%&gt;');" &gt;&lt;%=rs(2)%&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;%=rs(4)%&gt;&amp;nbsp;&lt;/td&gt;
   
  &lt;/tr&gt;
  &lt;%
    i=i+1
    rs.movenext
    loop
  %&gt;  
&lt;/table&gt;

&lt;/form&gt;
&lt;form&gt;
&lt;p align="center"&gt;
  
  共&lt;%=rs.recordcount%&gt;记录
  &lt;%
    k=currentpage
    if k&lt;&gt;1 then
      response.write "[&lt;b&gt;"+"&lt;a href='noticelook.asp?page=1'&gt;首页&lt;/a&gt;&lt;/b&gt;]"
      response.write "[&lt;b&gt;"+"&lt;a href='noticelook.asp?page="+cstr(k-1)+"'&gt;上一页&lt;/a&gt;&lt;/b&gt;]"
    else
      response.write "[首页][上一页]"
    end if
    if k&lt;&gt;n then
      response.write "[&lt;b&gt;"+"&lt;a href='noticelook.asp?page="+cstr(k+1)+"'&gt;下一页&lt;/a&gt;&lt;/b&gt;]"
      response.write "[&lt;b&gt;"+"&lt;a href='noticelook.asp?page="+cstr(n)+"'&gt;尾页&lt;/a&gt;&lt;/b&gt;]"
    else
      response.write "[下一页][尾页]"
    end if
  %&gt;
  第&lt;%=currentpage%&gt;/&lt;%=n%&gt;页
  &amp;nbsp;转到第&amp;nbsp;&lt;select name="page"&gt;&lt;%for j=1 to n%&gt;&lt;option value="&lt;%=j%&gt;" &lt;%if j=currentpage then
    response.write "selected"
    end if%&gt;&gt;&lt;%=j%&gt;&lt;/option&gt;
    &lt;%next%&gt;&lt;/select&gt;&amp;nbsp;页&amp;nbsp;&lt;input type=submit name="submit" value="go"&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;%
  end if
  rs.close
  set rs=nothing
%&gt;
&lt;/body&gt;
&lt;%
else
   response.write "&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;"
   response.write "&lt;center&gt;没有相应的公告!&lt;/center&gt;"
end if%&gt;
&lt;/html&gt;
2006-08-31 15:51
快速回复:asp 怎么分页?我这个分页代码为什么sql语句不能带参数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014066 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved