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 "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
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>" & 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 <> TotalNumber-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 < Totalnumber 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