激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - ASP教程 - Access 2000 數(shù)據(jù)庫 80 萬記錄通用快速分頁類

Access 2000 數(shù)據(jù)庫 80 萬記錄通用快速分頁類

2019-10-21 10:21asp技術網(wǎng) ASP教程

主要思路: 用一條語句統(tǒng)計(Count)出記錄數(shù)(而不在查詢時獲得 RecordCount 屬性), 緩存在 Cookies 中, 跳轉(zhuǎn)時就不用再次統(tǒng)計. 使用 ADO 的 AbsolutePage 屬性進行頁面跳轉(zhuǎn)即可. 為方便調(diào)用而寫成類, 代碼主要地方已有說明

代碼本人優(yōu)化過,測試通過

主要思路:用一條語句統(tǒng)計(Count)出記錄數(shù)(而不在查詢時獲得RecordCount屬性),緩存在Cookies中,跳轉(zhuǎn)時就不用再次統(tǒng)計.使用ADO的AbsolutePage屬性進行頁面跳轉(zhuǎn)即可.為方便調(diào)用而寫成類,代碼主要地方已有說明

硬件環(huán)境:AMDAthlonXP2600+,256DDR

軟件環(huán)境:MSWindows2000AdvancedServer+IIS5.0+Access2000+IE6.0

測試結果:初次運行在250(首頁)-400(末頁)毫秒,(記錄數(shù)緩存后)在頁面間跳轉(zhuǎn)穩(wěn)定在47毫秒以下.第1頁跳到最后一頁不多于350毫秒

適用范圍:用于普通分頁.不適用于有較復雜的查詢時:如條件為"[Title]Like’%最愛%’",查詢的時間大大增加,就算Title字段作了索引也沒用.:(

  1. <%  
  2. Dim intDateStart  
  3. intDateStart = Timer()  
  4.  
  5. Rem ## 打開數(shù)據(jù)庫連接  
  6. Rem #################################################################  
  7. function f__OpenConn()  
  8. Dim strDbPath  
  9. Dim connstr  
  10. strDbPath = "fenye/db.mdb"  
  11. connstr  = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="  
  12. connstr  = connstr & Server.MapPath(strDbPath)  
  13. Set conn  = Server.CreateObject("Adodb.Connection")  
  14. conn.open connstr  
  15. End function  
  16. Rem #################################################################  
  17.  
  18. Rem ## 關閉數(shù)據(jù)庫連接  
  19. Rem #################################################################  
  20. function f__CloseConn()  
  21. If IsObject(conn) Then  
  22. conn.close  
  23. End If  
  24. Set conn = nothing  
  25. End function  
  26. Rem #################################################################  
  27. Rem 獲得執(zhí)行時間  
  28. Rem #################################################################  
  29. function getTimeOver(iflag)  
  30. Dim tTimeOver  
  31. If iflag = 1 Then  
  32. tTimeOver = FormatNumber(Timer() - intDateStart, 6, true)  
  33. getTimeOver = " 執(zhí)行時間: " & tTimeOver & " 秒"  
  34. Else  
  35. tTimeOver = FormatNumber((Timer() - intDateStart) * 1000, 3, true)  
  36. getTimeOver = " 執(zhí)行時間: " & tTimeOver & " 毫秒"  
  37. End If  
  38. End function  
  39. Rem #################################################################  
  40. Class Cls_PageView  
  41. Private sbooInitState  
  42. Private sstrCookiesName  
  43. Private sstrPageUrl  
  44. Private sstrPageVar  
  45. Private sstrTableName  
  46. Private sstrFieldsList  
  47. Private sstrCondiction  
  48. Private sstrOrderList  
  49. Private sstrPrimaryKey  
  50. Private sintRefresh  
  51.  
  52. Private sintRecordCount  
  53. Private sintPageSize  
  54. Private sintPageNow  
  55. Private sintPageMax  
  56.  
  57. Private sobjConn  
  58.  
  59. Private sstrPageInfo  
  60.  
  61. Private Sub Class_Initialize  
  62. Call ClearVars()  
  63. End Sub  
  64.  
  65. Private Sub class_terminate()  
  66. Set sobjConn = nothing  
  67. End Sub  
  68.  
  69. Public Sub ClearVars()  
  70. sbooInitState = False  
  71. sstrCookiesName = ""  
  72. sstrPageUrl = ""  
  73. sstrPageVar = "page"  
  74. sstrTableName = ""  
  75. sstrFieldsList = ""  
  76. sstrCondiction = ""  
  77. sstrOrderList = ""  
  78. sstrPrimaryKey = ""  
  79. sintRefresh = 0  
  80.  
  81. sintRecordCount = 0  
  82. sintPageSize = 0  
  83. sintPageNow = 0  
  84. sintPageMax = 0  
  85. End Sub  
  86.  
  87. Rem ## 保存記錄數(shù)的 Cookies 變量  
  88. Public Property Let strCookiesName(Value)  
  89. sstrCookiesName = Value  
  90. End Property  
  91.  
  92. Rem ## 轉(zhuǎn)向地址  
  93. Public Property Let strPageUrl(Value)  
  94. sstrPageUrl = Value  
  95. End Property  
  96.  
  97. Rem ## 表名  
  98. Public Property Let strTableName(Value)  
  99. sstrTableName = Value  
  100. End Property  
  101.  
  102. Rem ## 字段列表  
  103. Public Property Let strFieldsList(Value)  
  104. sstrFieldsList = Value  
  105. End Property  
  106.  
  107. Rem ## 查詢條件  
  108. Public Property Let strCondiction(Value)  
  109. If Value <> "" Then  
  110. sstrCondiction = " WHERE " & Value  
  111. Else  
  112. sstrCondiction = ""  
  113. End If  
  114. End Property  
  115.  
  116. Rem ## 排序字段, 如: [ID] ASC, [CreateDateTime] DESC  
  117. Public Property Let strOrderList(Value)  
  118. If Value <> "" Then  
  119. sstrOrderList = " ORDER BY " & Value  
  120. Else  
  121. sstrOrderList = ""  
  122. End If  
  123. End Property  
  124.  
  125. Rem ## 用于統(tǒng)計記錄數(shù)的字段  
  126. Public Property Let strPrimaryKey(Value)  
  127. sstrPrimaryKey = Value  
  128. End Property  
  129.  
  130. Rem ## 每頁顯示的記錄條數(shù)  
  131. Public Property Let intPageSize(Value)  
  132. sintPageSize = toNum(Value, 20)  
  133. End Property  
  134.  
  135. Rem ## 數(shù)據(jù)庫連接對象  
  136. Public Property Let objConn(Value)  
  137. Set sobjConn = Value  
  138. End Property  
  139.  
  140. Rem ## 當前頁  
  141. Public Property Let intPageNow(Value)  
  142. sintPageNow = toNum(Value, 1)  
  143. End Property  
  144.  
  145. Rem ## 頁面參數(shù)  
  146. Public Property Let strPageVar(Value)  
  147. sstrPageVar = Value  
  148. End Property  
  149.  
  150. Rem ## 是否刷新. 1 為刷新, 其他值則不刷新  
  151. Public Property Let intRefresh(Value)  
  152. sintRefresh = toNum(Value, 0)  
  153. End Property  
  154.  
  155. Rem ## 獲得當前頁  
  156. Public Property Get intPageNow()  
  157. intPageNow = singPageNow  
  158. End Property  
  159.  
  160. Rem ## 分頁信息  
  161. Public Property Get strPageInfo()  
  162. strPageInfo = sstrPageInfo  
  163. End Property  
  164.  
  165. Rem ## 取得記錄集, 二維數(shù)組或字串, 在進行循環(huán)輸出時必須用 IsArray() 判斷  
  166. Public Property Get arrRecordInfo()  
  167. If Not sbooInitState Then  
  168. Exit Property  
  169. End If  
  170.  
  171. Dim rs, sql  
  172. sql = "SELECT " & sstrFieldsList & _  
  173. " FROM " & sstrTableName & _  
  174. sstrCondiction & _  
  175. sstrOrderList  
  176.  
  177. Set rs = Server.CreateObject("Adodb.RecordSet")  
  178. rs.open sql, sobjConn, 1, 1  
  179. If Not(rs.eof or rs.bof) Then  
  180. rs.PageSize = sintPageSize  
  181. rs.AbsolutePage = sintPageNow  
  182. If Not(rs.eof or rs.bof) Then  
  183. arrRecordInfo = rs.getrows(sintPageSize)  
  184. Else  
  185. arrRecordInfo = ""  
  186. End If  
  187. Else  
  188. arrRecordInfo = ""  
  189. End If  
  190. rs.close  
  191. Set rs = nothing  
  192. End Property  
  193.  
  194. Rem ## 初始化記錄數(shù)  
  195. Private Sub InitRecordCount()  
  196. sintRecordCount = 0  
  197. If Not(sbooInitState) Then Exit Sub  
  198. Dim sintTmp  
  199. sintTmp = toNum(request.Cookies("_xp_" & sstrCookiesName), -1)  
  200. If ((sintTmp < 0) Or (sintRefresh = 1))Then  
  201. Dim sql, rs  
  202. sql = "SELECT COUNT(" & sstrPrimaryKey & ")" & _  
  203. " FROM " & sstrTableName & _  
  204. sstrCondiction  
  205. Set rs = sobjConn.execute(sql)  
  206. If rs.eof or rs.bof Then  
  207. sintTmp = 0  
  208. Else  
  209. sintTmp = rs(0)  
  210. End If  
  211. sintRecordCount = sintTmp  
  212.  
  213. response.Cookies("_xp_" & sstrCookiesName) = sintTmp  
  214. Else  
  215. sintRecordCount = sintTmp  
  216. End If  
  217. End Sub  
  218.  
  219. Rem ## 初始化分頁信息  
  220. Private Sub InitPageInfo()  
  221. sstrPageInfo = ""  
  222. If Not(sbooInitState) Then Exit Sub  
  223.  
  224. Dim surl     
  225. surl = sstrPageUrl     
  226. If Instr(1, surl, "?", 1) > 0 Then  
  227. surl = surl & "&" & sstrPageVar & "="  
  228. Else  
  229. surl = surl & "?" & sstrPageVar & "="  
  230. End If  
  231.  
  232. If sintPageNow <= 0 Then sintPageNow = 1  
  233. If sintRecordCount mod sintPageSize = 0 Then  
  234. sintPageMax = sintRecordCount \ sintPageSize  
  235. Else  
  236. sintPageMax = sintRecordCount \ sintPageSize + 1  
  237. End If  
  238. If sintPageNow > sintPageMax Then sintPageNow = sintPageMax  
  239.  
  240. If sintPageNow <= 1 then  
  241. sstrPageInfo = "首頁 上一頁"  
  242. Else  
  243. sstrPageInfo = sstrPageInfo & " <a href=""" & surl & "1"">首頁</a>"  
  244. sstrPageInfo = sstrPageInfo & " <a href=""" & surl & (sintPageNow - 1) & """>上一頁</a>"  
  245. End If  
  246.  
  247. If sintPageMax - sintPageNow < 1 then  
  248. sstrPageInfo = sstrPageInfo & " 下一頁 末頁 "  
  249. Else  
  250. sstrPageInfo = sstrPageInfo & " <a href=""" & surl & (sintPageNow + 1) & """>下一頁</a> "  
  251. sstrPageInfo = sstrPageInfo & " <a href=""" & surl & sintPageMax & """>末頁</a> "  
  252. End If  
  253.  
  254. sstrPageInfo = sstrPageInfo & " 頁次:<strong><font color=""#990000"">" & sintPageNow & "</font> / " & sintPageMax & " </strong>"  
  255. sstrPageInfo = sstrPageInfo & " 共 <strong>" & sintRecordCount & "</strong> 條記錄 <strong>" & sintPageSize & "</strong> 條/頁 "  
  256. End Sub  
  257.  
  258. Rem ## 長整數(shù)轉(zhuǎn)換  
  259. Private function toNum(s, Default)  
  260. s = s & ""  
  261. If s <> "" And IsNumeric(s) Then  
  262. toNum = CLng(s)  
  263. Else  
  264. toNum = Default  
  265. End If  
  266. End function  
  267.  
  268. Rem ## 類初始化  
  269. Public Sub InitClass()  
  270. sbooInitState = True  
  271. If Not(IsObject(sobjConn)) Then sbooInitState = False  
  272. Call InitRecordCount()  
  273. Call InitPageInfo()     
  274. End Sub  
  275. End Class  
  276.  
  277.  
  278. Dim strLocalUrl  
  279. strLocalUrl = request.ServerVariables("SCRIPT_NAME")  
  280.  
  281. Dim intPageNow  
  282. intPageNow = request.QueryString("page")  
  283.  
  284. Dim intPageSize, strPageInfo  
  285. intPageSize = 30  
  286.  
  287. Dim arrRecordInfo, i  
  288. Dim Conn  
  289. f__OpenConn  
  290. Dim clsRecordInfo  
  291. Set clsRecordInfo = New Cls_PageView  
  292.  
  293. clsRecordInfo.strTableName = "[table1]"  
  294. clsRecordInfo.strPageUrl = strLocalUrl  
  295. clsRecordInfo.strFieldsList = "[ID], [aaaa], [bbbb], [cccc]"  
  296. clsRecordInfo.strCondiction = "[ID] < 10000"  
  297. clsRecordInfo.strOrderList = "[ID] ASC"  
  298. clsRecordInfo.strPrimaryKey = "[ID]"  
  299. clsRecordInfo.intPageSize = 20  
  300. clsRecordInfo.intPageNow = intPageNow  
  301.  
  302. clsRecordInfo.strCookiesName = "RecordCount"  
  303. clsRecordInfo.strPageVar = "page"  
  304.  
  305. clsRecordInfo.intRefresh = 0  
  306. clsRecordInfo.objConn = Conn  
  307. clsRecordInfo.InitClass  
  308.  
  309. arrRecordInfo = clsRecordInfo.arrRecordInfo  
  310. strPageInfo = clsRecordInfo.strPageInfo  
  311. Set clsRecordInfo = nothing  
  312. f__CloseConn  
  313. %>  
  314. <html>  
  315. <head>  
  316. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">  
  317. <title>分頁測試</title>  
  318. <style type="text/css">  
  319. <!--  
  320. .PageView {  
  321. font-size: 12px;  
  322. }  
  323. .PageView td {  
  324. border-right-style: solid;  
  325. border-bottom-style: solid;  
  326. border-right-color: #E0E0E0;  
  327. border-bottom-color: #E0E0E0;  
  328. border-right-width: 1px;  
  329. border-bottom-width: 1px;  
  330. }  
  331. .PageView table {  
  332. border-left-style: solid;  
  333. border-top-style: solid;  
  334. border-left-color: #E0E0E0;  
  335. border-top-color: #E0E0E0;  
  336. border-top-width: 1px;  
  337. border-left-width: 1px;  
  338. }  
  339. tr.Header {  
  340. background: #EFF7FF;  
  341. font-size: 14px;  
  342. font-weight: bold;  
  343. line-height: 120%;  
  344. text-align: center;  
  345. }  
  346. -->  
  347. </style>  
  348. <style type="text/css">  
  349. <!--  
  350. body {  
  351. font-size: 12px;  
  352. }  
  353. a:link {  
  354. color: #993300;  
  355. text-decoration: none;  
  356. }  
  357. a:visited {  
  358. color: #003366;  
  359. text-decoration: none;  
  360. }  
  361. a:hover {  
  362. color: #0066CC;  
  363. text-decoration: underline;  
  364. }  
  365. a:active {  
  366. color: #000000;  
  367. text-decoration: none;  
  368. }  
  369. table {  
  370. font-size: 12px;  
  371. }  
  372. -->  
  373. </style>  
  374. </head>  
  375. <body>  
  376. <table width="100%" border="0" cellspacing="0" cellpadding="4">  
  377.   <tr>  
  378.   <td> <%= strPageInfo%></td>  
  379. </tr>  
  380. </table>  
  381. <div class="PageView">  
  382.   <table width="100%" border="0" cellspacing="0" cellpadding="4">  
  383.     <tr class="Header">   
  384.     <td>ID</td>  
  385.     <td>描述</td>  
  386.     <td>日期</td>  
  387.   </tr>  
  388. <%  
  389.   If IsArray(arrRecordInfo) Then  
  390.    For i = 0 to UBound(arrRecordInfo, 2)  
  391. %>  
  392.   <tr>  
  393.     <td> <%= arrRecordInfo(0, i)%></td>  
  394.     <td> <%= arrRecordInfo(1, i)%></td>  
  395.     <td> <%= arrRecordInfo(2, i)%></td>  
  396.   </tr>  
  397. <%  
  398.    Next  
  399.   End If  
  400. %>  
  401. </table>  
  402. </div>  
  403. <table width="100%" border="0" cellspacing="0" cellpadding="4">  
  404.   <tr>   
  405.   <td> <%= strPageInfo%></td>  
  406. </tr>  
  407. </table>  
  408. <table width="100%" border="0" cellspacing="0" cellpadding="4">  
  409.   <tr>   
  410.     <td align="center"> <%= getTimeOver(1)%></td>  
  411.   </tr>  
  412. </table>  
  413. </body>  
  414. </html> 

 

 

 

 

 

 

 

 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 91av在线免费播放 | 黄色一级毛片免费看 | xxxx8| 双性帝王调教跪撅打屁股 | 久久17 | av在线浏览 | 欧美伦理一区二区 | 国产69精品久久久久久 | 成人毛片一区二区三区 | 亚洲人成在线播放网站 | av在线1| 国产免费一区二区三区网站免费 | 91性视频 | 一区二区三视频 | 日韩电影视频 | 91久久91久久精品免观看 | 久草在线播放视频 | 日本一级特级 | 国产精品久久久免费看 | 九九视频精品在线观看 | 精品999www| 欧美zoofilia杂交videos | 超碰人人射 | 国产精品呻吟 | 88xx成人永久免费观看 | 欧美日韩手机在线观看 | 国产精品久久久久久久久久了 | 久久久久久片 | 亚洲精品久久久久www | 欧美国产一区二区三区 | 久草视频在线看 | 正在播放91 | chinese hd xxxx tube| 亚洲精品av在线 | 国产精品久久久久久久久久了 | 久久久久九九九女人毛片 | 国产91在线高潮白浆在线观看 | 欧美 videos粗暴 | 91精品国产日韩91久久久久久360 | 国产精品一区自拍 | 亚洲欧美日韩在线 |