当前位置: 首页 > 图文教程 > 网络编程 > ASP > 将ASP纪录集输出成n列的的表格形式显示的方法

ASP
ASP调用ORACLE存储过程并返回结果集
用ASP实现网页BBS
关于Global.asa文件的深入研究与session变量失效提示的具体方法
简易ASP+注册系统
防护手册:如何防止ASP木马在服务器上运行
用Visual Basic实现多画面播放功能之二
如何增强ASP程序性能(1)
如何增强ASP程序性能(2)
如何增强ASP程序性能(3)
ASP备份数据库
二十八条改善 ASP 性能和外观的技巧
在Form域中Post大于100K的数据
如何使用ASP制作模似动态生长的表单?
Microsoft IIS 真的如此「不安全」吗?(1)
Microsoft IIS 真的如此「不安全」吗?(2)
Microsoft IIS 真的如此「不安全」吗?(3)
Microsoft IIS 真的如此「不安全」吗?(4)
Microsoft IIS 真的如此「不安全」吗?(5)
关于页面和代码分离
ServerVariables 对路径的操作

将ASP纪录集输出成n列的的表格形式显示的方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 70 ::
收藏到网摘: n/a

 

前些日子有网友问:将ASP纪录集输出成n列的的表格形式显示的方法,现在写了一个,方便大家使用。
'定义变量
Dim cn,rs,Sql

Sql = "select CustomerID from Orders"

 '记录总数
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 "没有记录输出。"
'www.knowsky.com
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>&nbsp;</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