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

来源:asp之家 时间:2011-04-08 10:51:00 

 

'定义变量 
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 "没有记录输出。" 
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

标签:ASP,记录集,表格形式
0
投稿

猜你喜欢

  • MSSQL中递归SQL查询语句实例说明-

    2011-09-30 11:42:43
  • 正则表达式30分钟入门教程

    2007-08-27 10:38:00
  • 将多宿主计算机配置为SQL Server访问

    2011-01-04 16:17:00
  • 建立三层结构的ASP应用程序

    2009-01-21 19:41:00
  • Mysql中日期和时间函数介绍

    2008-05-24 08:16:00
  • Asp教程:Response对象

    2007-10-01 18:08:00
  • Instr函数与InstrRev函数的区别

    2008-07-07 16:53:00
  • 有时应该告诉我,但有时不应该告诉我

    2009-03-19 13:40:00
  • 逐步讲解向Access数据库上传且显示图片

    2008-11-28 16:51:00
  • 最新google pr查询接口

    2012-03-12 20:00:39
  • 网页设计细节不能丢

    2007-09-26 11:54:00
  • Oracle 数据库中创建合理的数据库索引

    2009-07-02 12:31:00
  • 跨浏览器使用剪贴板

    2008-09-27 13:26:00
  • asp开发Wap中的随笔

    2008-05-21 12:56:00
  • Overflow Auto && Position Relative

    2009-09-03 12:02:00
  • MySQL 数据库语句优化的原则

    2010-01-20 10:11:00
  • SQL Server 2005日志文件损坏的处理方法

    2008-12-02 14:36:00
  • 非常全面的实用JavaScript开发工具列表

    2010-01-05 16:44:00
  • ASP.NET教程第二讲:安装ASP.NET

    2007-08-07 11:59:00
  • 如何用CSS实现图像替换链接文本显示并保证链接可点击

    2011-03-03 12:37:00
  • asp之家 网络编程 m.aspxhome.com