asp读取ACCESS数据库表的前20条记录,然后分两行显示,每行10条记录,怎么编?

如题所述

第1个回答  2011-04-10
给你个例子:

<%dim shuliang
shuliang=20 '每行显示20条信息%>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<%set rs=server.CreateObject("adodb.recordset")
rs.open "select Top "&shuliang&" * from [表名]",conn,1,1 '表名就是调取数据库的名称 if rs.eof and rs.bof then
response.write "暂无数据"
'response.End
else
%>
<% if not rs.eof then
i=1
do while not rs.eof%>
<td valign="top"><table width="110" height="20" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="110"><%=rs("name")%></td>
</tr>
</table></td>
<%if i mod 10 = 0 then '这里的10就是每行显示数据的数量%>
</tr>
<%end if
rs.movenext
i=i+1
loop
rs.close
end if
end if
%>
</table>
第2个回答  2011-04-10
Dim RS:Set RS=Server.CreateObject("ADODB.RECORDSET")
Dim i:i=0
RS.Open "select top 20 from yourtable order by id",conn,1,3
IF Not RS.Eof Then
Do While Not RS.Eof
i=i+1
response.write "记录"
if i mod 10=0 then
response.write "<br />"
end if
Loop
End IF本回答被提问者和网友采纳
相似回答