How to display an ASP recordset as a tabular form of n columns

Source: Internet
Author: User

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

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.