some days ago, some netizens asked: the ASP recordset output into N columns of the form display method, now write a, convenient for everyone to use.
' Define variables
Dim Cn,rs,sql
SQL = "Select CustomerID from Orders"
' Total records
Dim Totalnumbe
Set cn = Server.CreateObject ("ADODB.") Connection ")
cn. Open "Provider=SQLOLEDB.1; User id=sa;initial catalog=northwind;data source=.; password=; "
Set rs = Server.CreateObject ("ADODB.") Recordset ")
Rs. Open Sql, CN, 3, 1
Totalnumber = Rs. RecordCount
If totalnumber = 0 Then
response.write "has no record output. '
Else
dim jj,nleft,ccol
jj = 0
ncol = 415
nleft = ncol-(totalnumber Mod Ncol
if nleft = ncol Then nleft = 0
response.write "<table border><tr>" & VbCrLf
&nbs P While not Rs. EOF
response.write "<td>" & rs ("CustomerID") & "</td>" & VbCrLf
' If (JJ Mod ncol) = (NCOL-1) and JJ <> TotalNumber-1 Then Response.Write "</tr><tr>" &am P VbCrLf
' If (JJ Mod ncol) = (NCOL-1) and JJ = totalnumber-1 Then Response.Write "</tr>" & VbCrLf
if (JJ Mod ncol) = (nCol-1) Then
if JJ <> Totalnumb Er-1 Then
response.write "</tr><tr>" & VBCrLf
else
response.write "</tr>" & vbCrLf
end if
end if
jj = JJ + 1
rs. MoveNext
wend
if nleft <> 0 and Nleft <> ncol Then
if Ncol < Totalnumbe R Then
for i = 1 to nleft
response.write "<td> </td> "& vbCrLf
next
end If
response.write" </tr> "& VbCrLf
end if
response.write "</table>"
End If
Rs. Close
Set rs = Nothing
CN. Close
Set cn = Nothing
Response.End