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

Source: Internet
Author: User
Show 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>" & VbC Rlf


' 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











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.