服务器之家

服务器之家 > 正文

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

时间:2019-09-18 10:38     来源/作者:asp教程网
  1. '定义变量  
  2. Dim cn,rs,Sql  
  3. Sql = "select CustomerID from Orders"  
  4. '记录总数  
  5. Dim TotalNumbe  
  6. Set cn = Server.CreateObject("ADODB.Connection")  
  7. cn.Open "Provider=SQLOLEDB.1;User ID=sa;Initial Catalog=NorthWind;Data Source=.;Password=;"  
  8. Set rs = Server.CreateObject("ADODB.Recordset")  
  9. rs.Open Sql, cn, 3, 1  
  10. TotalNumber = rs.RecordCount  
  11. If TotalNumber = 0 Then  
  12. Response.Write "没有记录输出。"  
  13. Else  
  14. Dim jj,nLeft,cCol  
  15. jj = 0  
  16. nCol = 415  
  17. nLeft = nCol- (TotalNumber Mod nCol)  
  18. If nLeft = nCol Then nLeft = 0  
  19. Response.Write "<table border><tr>" & vbCrLf  
  20. While not rs.EOF  
  21. Response.Write "<td>" & rs("CustomerID") & "</td>" & vbCrLf  
  22. 'If (jj Mod nCol) = (nCol - 1) And jj <> TotalNumber - 1 Then Response.Write "</tr><tr>" & vbCrLf  
  23. 'If (jj Mod nCol) = (nCol - 1) And jj = TotalNumber-1 Then Response.Write "</tr>" & vbCrLf  
  24. If (jj Mod nCol) = (nCol - 1) Then  
  25. If jj <> TotalNumber - 1 Then  
  26. Response.Write "</tr><tr>" & vbCrLf  
  27. Else  
  28. Response.Write "</tr>" & vbCrLf  
  29. End If  
  30. End If  
  31. jj = jj + 1  
  32. rs.MoveNext  
  33. Wend  
  34. If nLeft <> 0 And nLeft <> nCol Then  
  35. If nCol < TotalNumber Then  
  36. For i = 1 to nLeft  
  37. Response.Write "<td> </td>" & vbCrLf  
  38. Next  
  39. End If  
  40. Response.Write "</tr>" & vbCrLf  
  41. End If  
  42. Response.Write "</table>"  
  43. End If  
  44. rs.Close  
  45. Set rs = Nothing  
  46. cn.Close  
  47. Set cn = Nothing  
  48. Response.End 

相关文章

热门资讯

玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分
玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分 2019-06-21
华为nova5pro和p30pro哪个好 华为nova5pro和华为p30pro对比详情
华为nova5pro和p30pro哪个好 华为nova5pro和华为p30pro对比详情 2019-06-22
抖音撒撒累累是什么歌 撒撒累累张艺兴歌曲名字
抖音撒撒累累是什么歌 撒撒累累张艺兴歌曲名字 2019-06-05
男生常说24816是什么意思?女生说13579是什么意思?
男生常说24816是什么意思?女生说13579是什么意思? 2019-09-17
超A是什么意思 你好a表达的是什么
超A是什么意思 你好a表达的是什么 2019-06-06
返回顶部