ASP.net的ACCESS数据分页方案

access|asp.net|分页|数据

中国IT动力,最新最全的IT技术教程最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 未整理篇 | 技术讨论 ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql 服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证   当前位置: > 程序开发 > Web开发 > Asp > 综合文章ASP.net的ACCESS数据分页方案 作者:未知 时间:2005-06-23 12:12 出处:Blog 责编:chinaitpower               摘要:暂无
常用ASP.net分页为 DataGrid 控件 和 ADO分页

本分页为缓存唯一标识字段 只选出分页后的记录

对大量数据库分页提高了效率

NetPage.vb

Imports System.Web
Imports System.Data
Imports System.Data.OleDb

Namespace RyNetPage
    Public Class NetPage
        Inherits System.Web.UI.Page
        Private Conn As OleDbConnection
        Private DS As DataSet
        Private DT As DataTable
        Private SQLstr, ScriptName As String
        Private GetPage, PageCount, ListCount As Integer
        Private OrderStr, TableStr, IndexStr, ColumnStr, JscriptStr As String
        Private PageSizeNum As Integer
        Private PageIndex As String
        Public Sub New()
            ScriptName = "RyNetPage"
            PageSizeNum = 10
        End Sub
        Public WriteOnly Property ConnStr()
            Set(ByVal Value)
                Try
                    Conn = New OleDbConnection(Value)
                    Conn.Open()
                Catch ex As Exception
                    Echo(".New" & ex.Message.ToString)
                End Try
            End Set
        End Property
        Public WriteOnly Property Jscript() As String
            Set(ByVal Value As String)
                JscriptStr = Value
            End Set
        End Property
        Public WriteOnly Property PageSize() As String
            Set(ByVal Value As String)
                PageSizeNum = Convert.ToInt32(Value)
            End Set
        End Property
        Public WriteOnly Property Order() As String
            Set(ByVal Value As String)
                If AppCache("Order") <> Value Then
                    OrderStr = "Order " & Value
                    AppCache("Order") = OrderStr
                    WriteIndex()
                End If
            End Set
        End Property
        Public WriteOnly Property Table() As String
            Set(ByVal Value As String)
                TableStr = "[" & Value & "]"
            End Set
        End Property
        Public WriteOnly Property Index() As String
            Set(ByVal Value As String)
                IndexStr = Value
            End Set
        End Property
        Public WriteOnly Property Column() As String
            Set(ByVal Value As String)
                ColumnStr = Value
            End Set
        End Property
        Public ReadOnly Property RecordsCount() As Integer
            Get
                Try
                    WriteIndex()
                    DT = AppCache("Index")
                    Return DT.Rows.Count
                Catch ex As Exception
                    Echo(".RecordsCount " & ex.Message.ToString)
                End Try
            End Get
        End Property
        Public Function ShowRecords() As DataTable
            Try
                SQLstr = "Select " & ColumnStr & " From " & TableStr & PageWhere()
                WriteIndex()
                Dim Adapt As OleDbDataAdapter
                Adapt = New OleDbDataAdapter(SQLstr, Conn)
                DS = New DataSet
                DS.Clear()
                Adapt.Fill(DS)
                Return DS.Tables(0)
            Catch ex As Exception
                Echo(".ShowRecords " & ex.Message.ToString)
            End Try
        End Function
        Public Function ShowPage(Optional ByVal GetStr As String = "") As String
            Dim Temp As String
            Temp = "<Script Language=""Jscript"" Src=""" & JscriptStr & """></Script>" & Chr(13)
            Temp += "<Script Language=""Jscript"">Pages(" & GetPage + 1 & "," & PageCount & "," & ListCount & ",'" & GetStr & "Page')</Script>"
            Return Temp
        End Function
        Public Sub Clear()
            AppCache("Index") = Nothing
        End Sub
        Private Function PageWhere() As String
            Try
                Dim EPage As Integer
                Dim i As Integer
                DT = AppCache("Index")
                GetPage = Convert.ToInt32(HttpContext.Current.Request.QueryString("Page"))
                ListCount = RecordsCount()
                PageCount = CInt(Fix(ListCount / PageSizeNum) + 1)
                If ListCount Mod PageSizeNum = 0 Then
                    PageCount = PageCount - 1
                End If
                If GetPage = 0 Or PageCount < GetPage Then
                    GetPage = 1
                End If
                GetPage = GetPage - 1
                If ListCount < PageSizeNum Or GetPage = PageCount Then
                    EPage = ListCount - 1
                Else
                    EPage = (GetPage * PageSizeNum + PageSizeNum) - 1
                End If
                For i = (GetPage * PageSizeNum) To EPage
                    PageIndex += DT.Rows(i)(0) & ","
                    If i = ListCount - 1 Then Exit For
                Next
                PageIndex = Left(PageIndex, Len(PageIndex) - 1)
                Return " Where " & IndexStr & " In(" & PageIndex & ")"
            Catch ex As Exception
                Echo(".PageWhere " & ex.Message.ToString)
            End Try
        End Function
        Private Sub WriteIndex()
            Try
                If (AppCache("Index") Is Nothing) Then
                    Dim Adapt As OleDbDataAdapter
                    Adapt = New OleDbDataAdapter("Select " & IndexStr & " From " & TableStr & OrderStr, Conn)
                    DS = New DataSet
                    DS.Clear()
                    Adapt.Fill(DS)
                    AppCache("Index") = DS.Tables(0)
                End If
            Catch ex As Exception
                Echo(".WriteIndex " & ex.Message.ToString)
            End Try
        End Sub
        Private Property AppCache(ByVal SetName As String)
            Get
                Return HttpContext.Current.Application.Get(ScriptName & "_" & TableStr & "_" & SetName)
            End Get
            Set(ByVal Value)
                HttpContext.Current.Application.Lock()
                HttpContext.Current.Application.Set(ScriptName & "_" & TableStr & "_" & SetName, Value)
                HttpContext.Current.Application.UnLock()
            End Set
        End Property
        Private Sub Echo(ByVal Value As String)
            Dispose()
            HttpContext.Current.Response.Write(Value)
            HttpContext.Current.Response.End()
        End Sub
        Protected Overrides Sub Finalize()
            MyBase.Finalize()
            Dispose()
        End Sub
        Public Overrides Sub Dispose()
            If Not (Conn Is Nothing) Then
                Conn.Dispose()
            End If
        End Sub
    End Class
End Namespace

Pages.js

function Pages(requestpage,MaxPage,RecordCount,PageName){
var p,ii;
if((requestpage-1)%10==0)
 p=(requestpage-1)/10;
else
 p=parseInt((requestpage-1)/10);
 document.write('<font class="smalltxt">');
 document.write(' '+RecordCount+' ');
 document.write(' '+requestpage+'/'+MaxPage+'  Pages ');
if(requestpage==1)
 document.write('<');
else
 document.write('<a href=?'+PageName+'=1 title=首页><</a>');
 if(p*10>0)
 {
  document.write(' <a href=?'+PageName+'='+p*10+' title=上十页>..</a>');
 }
 for(ii=p*10+1;ii<=p*10+10;ii++)
 {
  if(ii==requestpage)
  {
   document.write (' <u><font color="#CC0033">'+ii+'</font></u> ');
  }
  else
  {
   document.write (' <a href=?'+PageName+'='+ii+'>'+ii+'</a> ');
  }
 if(ii==MaxPage)
  break;
 }

if(ii<MaxPage)
{
 document.write('<a href=?'+PageName+'='+ii+' title=下十页>..</a> ');
 if(requestpage==MaxPage)
  document.write('>');
 else
  document.write('<a href=?'+PageName+'='+MaxPage+' title=尾页>></a>');
}
 document.write('</font> <input class="sBut" type="text" size="1" name="page" value="'+requestpage+'" class="PageInput"> <input class="sBut" type="button" value="GO"  >');
}

调用示范

Dim Net = New NetPage

        ConnStr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Server.MapPath("DataBase/RYBBS.mdb")
        Dim i As Integer
        Net.Jscript = Server.MapPath("Jscript/Pages.js") 'JS分页函数地址
        Net.ConnStr = ConnStr '连接数据库
        Net.PageSize = 20 '每页显示数
        Net.Table = "Test" '表名
        Net.Index = "ID" '唯一标识字段名
        Net.Column = "ID,Title,Content" '要显示的字段名
        Net.Order = "By ID Desc" '排序
        Dim RS As DataTable
        RS = Net.ShowRecords '调出分页后的记录
        Response.Write("<table>")
        For i = 0 To RS.Rows.Count - 1
            Response.Write("<tr>" & Chr(13))
            Response.Write("<td>" & RS.Rows(i)(0) & "</td><td>" & RS.Rows(i)(1) & "</td><td>" & RS.Rows(i)(2) & "</td>" & Chr(13))
            Response.Write("</tr>" & Chr(13))
        Next
        Response.Write("<table>" & Chr(13))
        Response.Write(Net.ShowPage("ID=20&") & "<br>") 'ID=20&为一同传递的其它分页参数
        Response.Write(FormatNumber(Timer - Run, 6))

时间: 2024-11-29 22:03:47

ASP.net的ACCESS数据分页方案的相关文章

asp代码实现access数据导出到excel文件

  asp代码实现access数据导出到excel文件: 一,下面是导出XLS格式 <%  dim referer  referer = Request.ServerVariables("HTTP_REFERER")  Dim CName,action  action=request.Form("action")  CName="../../Excel/"  dim daytime  'daytime=year(now())&&qu

asp.net实现access数据库分页的方法_实用技巧

asp.net操作access数据库是常见的数据库操作应用,本文就来实例讲解一下asp.net实现access数据库分页的方法.希望对大家的asp.net程序设计能有所帮助. 具体实例代码如下: <divclass="page"id="ctrlRecordPage"> 总<asp:LabelID="Zpage"runat="server"Text="1"></asp:Label

asp 用存储过程实现数据分页

存储过程|分页|数据 一.创建表 tiku_koushi if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tiku_koushi]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [dbo].[tiku_koushi]GO CREATE TABLE [dbo].[tiku_koushi] ([id] [int] IDENTITY (1, 1)

asp.net 学习日记数据分页

asp.net|分页|数据   想来学习 .net 也2个月了吧,最初遇到的一个问题就是分页程序获取当前页的数据并支持字段排序而且支持搜索时的 Where 语句 在网上搜了 很久也没找到,也在 Asp.net 的一些论坛上发过帖子也许是那些高手懒得理我吧(做菜鸟就是难)也许是我找东西的能力有问题,但我却找到了以下SQL 的 存储过程.  SET @page = (@page-1) * @pagesize + 1  EXEC sp_cursoropen @P1 output, @strSQL EX

Asp用存储过程实现数据分页

一.创建表 tiku_koushi if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tiku_koushi]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [dbo].[tiku_koushi]GO CREATE TABLE [dbo].[tiku_koushi] ([id] [int] IDENTITY (1, 1) NOT NULL ,

在asp页面实现access数据表的按时间统计

问题描述 我在做一个出车的统计有这样一个表carzy:idcarhmchuchetimeguilaitime--1鲁000012014/12/2308:302014/12/2311:302鲁000022014/12/2408:002014/12/2410:303鲁000032014/12/2408:102014/12/2410:204鲁000012014/12/2412:102014/12/2413:205鲁000012014/12/2415:102014/12/2418:20......我现在

asp.net(C#) Access 数据操作类_基础应用

复制代码 代码如下: using System; using System.Configuration; using System.Data; using System.Data.OleDb; using System.Xml; using System.Collections; namespace Website.Command { /// <summary> /// WSplus 的摘要说明. /// </summary> public class AccessClass :

ASP.NET技巧:access下的分页方案

access|asp.net|分页|技巧 具体不多说了,只贴出相关源码~ using System;using System.Collections.Generic;using System.Text;using System.Data;using System.Data.OleDb;using System.Web; /**//// <summary>/// 名称:access下的分页方案(仿sql存储过程)/// 作者:cncxz(虫虫)/// blog:http://cncxz.cnbl

ASP.NET技巧:access下的分页方案_实用技巧

具体不多说了,只贴出相关源码~ using System;using System.Collections.Generic;using System.Text;using System.Data;using System.Data.OleDb;using System.Web; /**//// <summary>/// 名称:access下的分页方案(仿sql存储过程)/// 作者:cncxz(虫虫)/// blog:http://cncxz.cnblogs.com/// </summa