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 variable
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>" & VB CrLf
' 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