将SQL Server数据库中的记录显示在ASP Classic中的表中

时间:2011-11-29 03:05:06

标签: sql sql-server asp-classic

我能够在表格中显示SQL Server数据库中的记录。而现在,我正试图将它们分成3行和1行。 2列表。这意味着如果总共有两个记录,它们应该并排出现而不是一个接一个出现。我可以使用以下代码获得重复记录。

<%
Sub B00_DisplayRecords()
Do while not registerRS.eof
counter=counter+1
if counter=41 then
counter=0
counter=counter+1
end if
%>

<tr>    
   <th width="50" font class="tblhdr" style="width:400px;"><%=registerRS.Fields("SchoolId")%> - <%=registerRS.Fields("Organization")%></td>   
   <th width="50" font class="tblhdr" style="width:400px;"><%=registerRS.Fields("SchoolId")%> - <%=registerRS.Fields("Organization")%></td>   
</tr>    
<tr> 
   <td width="50" font class="pgcont" valing=left style="width:400px;" align="left">ProductId: <%=registerRS.Fields("ProductId")%></td>
   <td width="50" font class="pgcont" valing=left style="width:400px;" align="left">ProductId: <%=registerRS.Fields("ProductId")%></td>
</tr>
<tr>
   <td width="50" font class="pgcont" valing=left style="width:400px;" align="left">Qty: <%=registerRS.Fields("Qty")%></td>
   <td width="50" font class="pgcont" valing=left style="width:400px;" align="left">Qty: <%=registerRS.Fields("Qty")%></td>
</tr>
<tr>
   <td width="50" font class="pgcont" valing=left style="width:400px;" align="left">Class: <%=registerRS.Fields("class")%></td>
   <td width="50" font class="pgcont" valing=left style="width:400px;" align="left">Class: <%=registerRS.Fields("class")%></td>
</tr>        

<%
registerRS.movenext
loop
registerRS.close
set registerRS=nothing 
End sub
%>  

1 个答案:

答案 0 :(得分:3)

Do until rs.eof

    r = r + 1

    If r = 1 then
        Response.write "<tr>"
    End if

    ' data display

    If r = 3 then
        Response.write "</tr>"
    End if

    If r = 3 then r = 1

Rs.movenext
Loop

If r = 2 ' write extra td and end tr
If r = 1 ' write 2 td and end tr