How to output an ASP record set as a table with n columns
Source: Internet
Author: User
'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
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service