access下的分页方案(仿sql存储过程)
使用系统;使用 System.Collections.Generic;使用系统文本;使用系统数据;使用 System.Data.OleDb;使用系统.Web; /**//// summary /// 名称:access下的分页方案(仿sql存储过程) /// 作者:cncxz(虫虫) /// blog: http://cncxz.cn
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Web;
/**////
/// 名称:access下的分页方案(仿sql存储过程)
/// 作者:cncxz(虫虫)
/// 博客:
///
公共类 AdoPager
{
protected string m_ConnString;
protected OleDbConnection m_Conn;
public AdoPager()
{
CreateConn(string.Empty);
}
public AdoPager(string dbPath)
{
CreateConn(dbPath) );
}
private void CreateConn(string dbPath)
{
if (string.IsNullOrEmpty(dbPath))
{
string str = System.Configuration.ConfigurationManager.AppSettings[ "dbPath"] as string;
if (string.IsNullOrEmpty(str))
str = "~/App_Data/db.mdb";
m_ConnString = string.Format(@"Provider=Microsoft.Jet .OLEDB.4.0;数据源={0}", HttpContext.Current.Server.MapPath(str));
}
else
m_ConnString = string.Format(@"Provider=Microsoft.Jet. OLEDB.4.0;数据源={0}", dbPath);
m_Conn = new OleDbConnection(m_ConnString);
}
/**////
/// 打开连接
///
public void ConnOpen()
{
if (m_Conn.State != ConnectionState .Open)
m_Conn.Open();
}
/**////
/// 关闭连接
///
public void ConnClose()
{
if (m_Conn.State != ConnectionState.Closed)
m_Conn.Close();
}
private string recordID(string query, int passCount)
{
OleDbCommand cmd = new OleDbCommand(query, m_Conn);
string result = string.Empty;
using (IDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
if (passCount
{
结果 = " ," dr.GetInt32(0);
}
passCount--;
}
}
返回结果.Substring(1);
}
/**////
/// 获取当前页应该显示的记录,注意:查询中必须包含名为ID的自动编号列,若不符合你的要求,就修改一下源码吧 :)
///
/// 当前页码
/// 分页容量
/// 显示的字段
/// 查询字符串,支持联合查询
/// 查询条件,若有条件限制则必须以where 开头
/// 排序规则
/// 传出参数:总页数统计
/// 传出参数:总记录统计
///
public DataTable ExecutePager(int pageIndex, int pageSize, string showString, string queryString, string whereString, string orderString, out int pageCount, out int recordCount)
{
if (pageIndex < 1) pageIndex = 1;
if (pageSize < 1) pageSize = 10;
if (string.IsNullOrEmpty(showString)) showString = "*";
if (string.IsNullOrEmpty(orderString)) orderString = "ID desc";
ConnOpen();
string myVw = string.Format(" ( {0} ) tempVw ", queryString);
OleDbCommand cmdCount = new OleDbCommand(string.Format(" select count(0) as recordCount from {0} {1}", myVw, whereString), m_Conn);
recordCount = Convert.ToInt32(cmdCount.ExecuteScalar());
if ((recordCount % pageSize) > 0)
pageCount = recordCount / pageSize 1;
else
pageCount = recordCount / pageSize;
OleDbCommand cmdRecord;
if (pageIndex == 1)//第一页
{
cmdRecord = new OleDbCommand(string.Format("select top {0} {1} from {2} {3} order by {4} ", pageSize, showString, myVw, whereString, orderString), m_Conn);
}
else if (pageIndex > pageCount)//超出总页数
{
cmdRecord = new OleDbCommand(string.Format("select top {0} {1} from {2} {3} order by {4} ", pageSize, showString, myVw, "where 1=2", orderString), m_Conn);
}
else
{
int pageLowerBound = pageSize * pageIndex;
int pageUpperBound = pageLowerBound - pageSize;
string recordIDs = recordID(string.Format("select top {0} {1} from {2} {3} order by {4} ", pageLowerBound, "ID", myVw, whereString, orderString), pageUpperBound);
cmdRecord = new OleDbCommand(string.Format("select {0} from {1} where id in ({2}) order by {3} ", showString, myVw, recordIDs, orderString), m_Conn);
}
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(cmdRecord);
DataTable dt=new DataTable();
dataAdapter.Fill(dt);
ConnClose();
return dt;
}
}
还有调用示例:html代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
代码隐藏代码示例
使用 System;
使用 System.Data;
使用 System.Configuration;
使用 System.Web;
使用 System.Web.Security;
使用System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Web.UI.WebControls.WebParts;
使用 System.Web.UI.HtmlControls;
使用 System.集合.通用;
公共部分类 _Default : System.Web.UI.Page
{
private AdoPager mm_Pager;
protected AdoPager m_Pager
{
get{
if (mm_Pager == null)
mm_Pager = new AdoPager();
return mm_Pager;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
LoadData();
}
private int pageIndex = 1;
private int pageSize = 20;
private int pageCount = -1;
private int记录计数 = -1;
private void LoadData()
{
string strQuery = "从 tableTest 中选择 a.*,b.KindText a left join tableKind b on a.KindCode=b.KindCode ";
string strShow = "ID,主题,KindCode,KindText";
DataTable dt = m_Pager.ExecutePager(pageIndex, pageSize, strShow, strQuery, "", "ID desc", out pageCount, out recordCount);
GridView1.DataSource = dt;
GridView1. DataBind();
Label1.Text = string.Format("共{0}条记录,每页{1}条,页次{2}/{3}",recordCount,pageSize,pageIndex,pageCount);
}
protected void btnJump_Click(object sender, EventArgs e)
{
int.TryParse(txtPageSize.Text, out pageIndex);
LoadData();
}
}

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

如何在 Apache 中配置 Zend?在 Apache Web 服务器中配置 Zend Framework 的步骤如下:安装 Zend Framework 并解压到 Web 服务器目录中。创建 .htaccess 文件。创建 Zend 应用程序目录并添加 index.php 文件。配置 Zend 应用程序(application.ini)。重新启动 Apache Web 服务器。

vProcesserazrabotkiveb被固定,мнелостольностьстьс粹馏标д都LeavallySumballanceFriablanceFaumDoptoMatification,Čtookazalovnetakprosto,kakaožidal.posenesko

有效监控和防御恶意网站访问对于Debian系统的Apache服务器至关重要。Apache访问日志是识别此类威胁的关键信息来源。本文将指导您如何分析日志并采取防御措施。识别恶意访问行为Debian系统的Apache访问日志通常位于/var/log/apache2/access.log。您可以通过多种方法分析日志:日志文件位置确认:首先,请确认您的Apache访问日志的准确位置,它可能因系统配置而略有不同。命令行工具分析:使用grep命令搜索特定模式,例如grep"404"

Apache服务器是强大的Web服务器软件,充当浏览器与网站服务器间的桥梁。1. 它处理HTTP请求,根据请求返回网页内容;2. 模块化设计允许扩展功能,例如支持SSL加密和动态网页;3. 配置文件(如虚拟主机配置)需谨慎设置,避免安全漏洞,并需优化性能参数,例如线程数和超时时间,才能构建高性能、安全的Web应用。

Nginx 限流问题可通过以下方法解决:使用 ngx_http_limit_req_module 限制请求次数;使用 ngx_http_limit_conn_module 限制连接数;使用第三方模块(ngx_http_limit_connections_module、ngx_http_limit_rate_module、ngx_http_access_module)实现更多限流策略;使用云服务(Cloudflare、Google Cloud Rate Limiting、AWS WAF)进行 DD

Nginx性能监控与故障排查主要通过以下步骤进行:1.使用nginx-V查看版本信息,并启用stub_status模块监控活跃连接数、请求数和缓存命中率;2.利用top命令监控系统资源占用,iostat和vmstat分别监控磁盘I/O和内存使用情况;3.使用tcpdump抓包分析网络流量,排查网络连接问题;4.合理配置worker进程数,避免并发处理能力不足或进程上下文切换开销过大;5.正确配置Nginx缓存,避免缓存大小设置不当;6.通过分析Nginx日志,例如使用awk和grep命令或ELK

SQL用于与MySQL数据库交互,实现数据的增、删、改、查及数据库设计。1)SQL通过SELECT、INSERT、UPDATE、DELETE语句进行数据操作;2)使用CREATE、ALTER、DROP语句进行数据库设计和管理;3)复杂查询和数据分析通过SQL实现,提升业务决策效率。

本文介绍了如何分析Nginx日志以提升网站性能和用户体验。1.理解Nginx日志格式,例如时间戳、IP地址、状态码等;2.使用awk等工具解析日志,统计访问量、错误率等指标;3.根据需求编写更复杂的脚本或使用更高级工具,例如goaccess,分析不同维度的数据;4.对于海量日志,考虑使用Hadoop或Spark等分布式框架。通过分析日志,可以识别网站访问模式、改进内容策略,并最终优化网站性能和用户体验。
