小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

asp + oracle 分頁方法 (不用存儲過程)

 天落雨 2006-01-17
 

asp 中查詢 oracle數(shù)據(jù)庫 的分頁程序,沒有用存儲過程,效率還可以。

代碼如下:

‘‘‘‘  塞北的雪  分頁利器(oracle)  不用存儲過程   -------------------------

‘其中注釋中有 ###的需要用戶設(shè)置
‘其中注釋中有 參數(shù)傳遞 ** 的 說明要通過參數(shù) 傳遞。


‘定義變量
dim tOption                  ‘查詢條件
dim tOrder                   ‘排序字符串     
dim tOrderField              ‘排序字段        可通過參數(shù)獲得:order_field
dim tOrderDirection          ‘排序方向        可通過參數(shù)獲得:order_direction

dim tPageSize                ‘頁大小
dim tTotalCount              ‘總記錄數(shù)        可通過參數(shù)獲得:t_count
dim tPageCount               ‘頁數(shù)
dim tCurPage                 ‘當(dāng)前頁號        可通過參數(shù)獲得:page

dim tTableName               ‘表或者視圖名

dim tFieldList               ‘查詢的字段列表
dim tPageField               ‘用于分頁的字段

dim r_count                  ‘查得的記錄數(shù)


set rs=server.createobject("adodb.recordset")        ‘記錄集對象

‘排序處理
tOrderField=Request("order_field")                   ‘獲得排序字段(參數(shù)傳遞 **)
tOrderDirection=Request("order_dir")                 ‘獲得排序方向(參數(shù)傳遞 **)

if(tOrderField="") then tOrderField="item_code"       ‘ ### 設(shè)置默認(rèn)排序字段
if(tOrderDirection="") then tOrderDirection="asc"     ‘ ### 設(shè)置默認(rèn)排序方向

tOrder=" order by " & tOrderField & " " & tOrderDirection & " "   ‘生成排序字符串


‘定義參數(shù)
tPageSize=find_rs_count        ‘ ### 設(shè)置頁大小
tTableName="view_select1"      ‘ ### 設(shè)置與查詢的表格或視圖
tFieldList=" * "               ‘ ### 欲查詢的字段列表
tPageField="item_code"         ‘ ### 設(shè)置一個主鍵或唯一索引的字段 ,用于分頁計算


‘頁數(shù)處理
tCurPage=Request("page")             ‘獲得當(dāng)前頁(參數(shù)傳遞 **)
tTotalCount=Request("t_count")       ‘獲得總頁數(shù)(參數(shù)傳遞 **)

if(tCurPage="") then tCurPage=1
if(cint(tCurPage)=0) then tCurPage=1
if(tPageCount="") then tPageCount =1
if(cint(tPageCount)=0) then tPageCount=1

‘ 構(gòu)造查詢條件,根據(jù)具體的程序,肯定不一樣。但是最后的條件必須是“ where ??? ”
tOption=" issue_flag=‘Y‘"                      ‘ ### 設(shè)置條件
if f_c<>"" then tOPtion= tOPtion & f_c         ‘ ### 設(shè)置條件

if trim(tOption)="" then
     tOption = " where 1=1 "   ‘如果沒有條件,就自己加一個。
else
     tOption= " where " & tOPtion
end if

   
  
     ‘構(gòu)造查詢字符串,這個分頁程序的核心,此查詢串是我們只下載當(dāng)前頁所需的記錄
 
sss="select * from (select rownum r_n,temptable.* from (select  " & tFieldList & " from " & tTableName & " " & tOption & " " & tOrder & ") temptable ) where r_n between " & cstr((tCurPage -1) * tPageSize +1) & " and " & cstr(tCurPage * tPageSize)  
 
 ‘執(zhí)行主查詢,獲得相應(yīng)記錄集
 Call ConnDataBase()                     ‘  ### 建立數(shù)據(jù)庫連接
    rs.cursorlocation=3
    rs.open conStr,conn,3,1                 ‘執(zhí)行查詢
    r_count= rs.recordcount


   ‘當(dāng)還沒有查詢過總記錄數(shù)時 并且 總的記錄數(shù)超過了頁大小時 ,查詢當(dāng)前條件下的總的記錄數(shù)
   if(r_count>=tPageSize or tCurPage>1) and tTotalCount=0 then
      set rr=conn.execute("select count(*) from " & tTableName & " " & tOption)
      tTotalCount=rr(0)
      rr.close()
      set rr=nothing
   end if   
   if(cint(tTotalCount)=0) then tTotalCount=r_count ‘如果總記錄為0,將當(dāng)前差得的記錄集的記錄數(shù)設(shè)置為總記錄數(shù),說明當(dāng)前的總記錄數(shù)小于頁大小
  
   ‘利用頁大小和總記錄數(shù) 計算頁數(shù)
   if(cint(tTotalCount)>cint(tPageSize)) then
  tPageCount=cint((cint(tTotalCount) \ cint(tPageSize)))
  if(cint(tTotalCount) mod cint(tPageSize))>0 then
      tPageCount =tPageCount +1
  end if
   end if
 
   tCurPage=cint(tCurPage)
   tPageCount=cint(tPageCount)


‘  ---------------------------------------------------------------------

        這就是全部代碼,感興趣的朋友,可以研究一下,或者將他封裝起來,加上分頁導(dǎo)航等方法??傊?,希望此代碼能對大家有用。

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多