ASP中限制显示记录个数的问题 ( 积分: 50 )

Y

yyjqtww

Unregistered / Unconfirmed
GUEST, unregistred user!
<%
set dbconnection=Server.CREATEOBJECT(&quot;ADODB.CONNECTION&quot;)
DBPath = Server.MapPath(&quot;zz.mdb&quot;)
dbconnection.Open &quot;driver={Microsoft Access Driver (*.mdb)};dbq=&quot;
&amp;
DBPath
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.Open &quot;zz&quot;, dbconnection, adOpenDynamic, 3
%>
<html>
<head>
<title>前台如何显示数据库中的数据</title>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
</head>
<body>
<table width=&quot;100%&quot;
height=&quot;40&quot;
border=&quot;0&quot;
align=&quot;center&quot;
cellpadding=&quot;0&quot;
cellspacing=&quot;1&quot;
bgcolor=&quot;#FF9900&quot;>
<tr align=&quot;center&quot;
bgcolor=&quot;#6D9D4A&quot;>
<td width=&quot;25%&quot;><font color=&quot;#FFFFFF&quot;>发布时间</font></td>
<td width=&quot;25%&quot;><font color=&quot;#FFFFFF&quot;>用人单位</font></td>
<td width=&quot;25%&quot;><font color=&quot;#FFFFFF&quot;>职位</font></td>
<td width=&quot;25%&quot;><font color=&quot;#FFFFFF&quot;>工作地点</font></td>
</tr>
<%do
while not rs.eof %>
<tr align=&quot;center&quot;
bgcolor=&quot;#EBEBEB&quot;>
<td><font size=&quot;2&quot;><%=rs(&quot;fbrq&quot;)%></font></td>
<td><font size=&quot;2&quot;><%=rs(&quot;yrdw&quot;)%></font></td>
<td><font size=&quot;2&quot;><%=rs(&quot;zw&quot;)%></font></td>
<td><font size=&quot;2&quot;><%=rs(&quot;gzdd&quot;)%></font></td>
</tr>
<%
rs.movenext
LOOP
%>
</table>
 </body>
</html>
这样以后,DB中的所有记录都显示出来了。可是我只想显示例如前五条怎么办呢,因为没有SQL语句,所以用了rs.pagesize=5来设定,可是也不行。请大家帮帮忙!
谢谢!
 
Y

yyjqtww

Unregistered / Unconfirmed
GUEST, unregistred user!
<%
set dbconnection=Server.CREATEOBJECT(&quot;ADODB.CONNECTION&quot;)
DBPath = Server.MapPath(&quot;zz.mdb&quot;)
dbconnection.Open &quot;driver={Microsoft Access Driver (*.mdb)};dbq=&quot;
&amp;
DBPath
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.Open &quot;zz&quot;, dbconnection, adOpenDynamic, 3
%>
<html>
<head>
<title>前台如何显示数据库中的数据</title>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
</head>
<body>
<table width=&quot;100%&quot;
height=&quot;40&quot;
border=&quot;0&quot;
align=&quot;center&quot;
cellpadding=&quot;0&quot;
cellspacing=&quot;1&quot;
bgcolor=&quot;#FF9900&quot;>
<tr align=&quot;center&quot;
bgcolor=&quot;#6D9D4A&quot;>
<td width=&quot;25%&quot;><font color=&quot;#FFFFFF&quot;>发布时间</font></td>
<td width=&quot;25%&quot;><font color=&quot;#FFFFFF&quot;>用人单位</font></td>
<td width=&quot;25%&quot;><font color=&quot;#FFFFFF&quot;>职位</font></td>
<td width=&quot;25%&quot;><font color=&quot;#FFFFFF&quot;>工作地点</font></td>
</tr>
<%do
while not rs.eof %>
<tr align=&quot;center&quot;
bgcolor=&quot;#EBEBEB&quot;>
<td><font size=&quot;2&quot;><%=rs(&quot;fbrq&quot;)%></font></td>
<td><font size=&quot;2&quot;><%=rs(&quot;yrdw&quot;)%></font></td>
<td><font size=&quot;2&quot;><%=rs(&quot;zw&quot;)%></font></td>
<td><font size=&quot;2&quot;><%=rs(&quot;gzdd&quot;)%></font></td>
</tr>
<%
rs.movenext
LOOP
%>
</table>
 </body>
</html>
这样以后,DB中的所有记录都显示出来了。可是我只想显示例如前五条怎么办呢,因为没有SQL语句,所以用了rs.pagesize=5来设定,可是也不行。请大家帮帮忙!
谢谢!
 
C

chenybin

Unregistered / Unconfirmed
GUEST, unregistred user!
那你就select top 5 from table吧,然后post的时候把ID号也放上去,默认从0开始就可以了
我记得是用pagesize的,
 
C

chenybin

Unregistered / Unconfirmed
GUEST, unregistred user!
我以前是有个序号字段,然后select的时候判断这个序号的范围,希望对你有参考作用
 

楼兰

Unregistered / Unconfirmed
GUEST, unregistred user!
<%
set dbconnection=Server.CREATEOBJECT(&quot;ADODB.CONNECTION&quot;)
DBPath = Server.MapPath(&quot;zz.mdb&quot;)
dbconnection.Open &quot;driver={Microsoft Access Driver (*.mdb)};dbq=&quot;
&amp;
DBPath
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
sqlstr=&quot;select top 5 * from zz order by 发布时间 desc&quot;
rs.Open sqlstr,dbconnection,1,1
%>
 
Y

yyjqtww

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢chenybin和楼兰的帮助。通过楼兰的代码我已经解决了这个问题,通过chenybin我得到启发,以后在设计DB的时候应该多考虑一些。谢谢两位的帮忙!真的非常谢谢!
 
Y

yyjqtww

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 
顶部