存储过程分页
====================================================================================================================
第一步:存储过程
if object_id('calcpage','P') is not null
drop procedure calcpage
go
CREATE procedure calcpage
@prc int=20, --每页记录数
@tn nvarchar(4000), --表名
@my_where nvarchar(4000) --条件
AS
declare @mysql nvarchar(4000)
--行数和页数
set @mysql=N'select count(*) as rc,(count(*)/'+str(@prc)+N'+(case when count(*)%'+str(@prc)+N'>0 then 1 else 0 end)) as pc from '+@tn+N' where '+@my_where
execute (@mysql)
go
--分页 存储过程
if object_id('paging','P') is not null
drop procedure paging
go
CREATE procedure paging
@prc int=20, --每页记录数
@pi int=1, --页索引
@sn nvarchar(4000), --选择列名s,
@tn nvarchar(4000), --表名
@on nvarchar(4000), --排序列名
@my_where nvarchar(4000) --条件
AS
declare @mysql nvarchar(4000)
--中间页
set @mysql=N'
select * from
(select top '+str(@prc)+N' * from
(select top '+str(@prc*@pi)+N' '+@sn+N' from '+@tn+N' where '+@my_where+N'
order by '+@on+N' asc) a order by '+@on+N' desc) b
order by '+@on+N' asc'
execute (@mysql)
go
===========================================================================================================================
第二步:在DAL下建Aux.cs文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HxDAL
{
public class HxDALAux
{
/// 分页存储过程整体调用方法
///private void button1_Click(object sender, EventArgs e)
///{
/// int prc=20;int pi = 4; // 行/页; 页索引
/// HxDALAux aux = new HxDALAux();
/// int rc=0;int pc=0;
/// if(aux.GetCalcpageParam(prc, "products", "1=1", ref rc, ref pc))
/// {
/// if(rc>0 && pc>0)
/// {
/// System.Collections.ArrayList result=new System.Collections.ArrayList(prc);
/// if (aux.GetPagingParam(prc, pi, "productId,productName", "products", "productId", "1=1", ref result))
/// {
/// this.dataGridView1.DataSource = aux.GetPagingParamAux(result);
/// }
/// }
/// }
///}
private static string _cs = @"data source=.;initial catalog=db_ChnCity;integrated security=True";
public static string CS
{
get { return HxDALAux._cs; }
set { HxDALAux._cs = value; }
}
protected static System.Data.SqlClient.SqlConnection _cn = null;
/// <summary>
/// 返回算页参数,调用方法:
/// int prc=20;int pi = 4;
/// HxDALAux aux = new HxDALAux();
/// int rc=0;int pc=0;
/// if(aux.GetCalcpageParam(prc, "products", "1=1", ref rc, re
你可能喜欢
- Java笔记
- oracle存储过程
- mysql存储过程
- 存储过程写法
- 存储过程教程
- 存储过程实例
- 存储过程语法
- Java学习笔记26页
- Java工作笔记(必看经典)30页
- Java学习笔记8页
- Java基础学习笔记整理42页
- Java反射学习笔记整理16页
- 简明Java笔记29页
- oracle存储过程的设计4页
- oracle函数存储过程教程25页
- oracle函数及存储过程教程11页
- oracle存储过程语法21页
- oracle数据库存储过程文档63页
- oracle_存储过程练习题8页
- mysql存储过程.详细说明,java代码调用过程6页
- mysql 5.0存储过程学习总结8页
- mysql 5.0存储过程学习总结1页
- mysql的存储过程2页
- mysql分页存储过程4页
- php与mysql存储过程 详解4页
- Oracle存储过程(增、删、改)写法2页
- sqlserver存储过程循环写法3页
- ASP中调用存储过程、语法、写法-sql server数据库11页
- SQL语句分页存储过程的写法1页
- sqlserver的存储过程的写法1页
- 存储过程写法5页
- oracle函数存储过程教程25页
- oracle函数及存储过程教程11页
- SQL存储过程入门教程30页
- Oracle数据库_入门教程(二)_子程序(存储过程和函数)3页
- 存储过程教程31页
- mysql_5.5.8_教程_08 存储过程procedure 与 存储函数function1页
- ORACLE存储过程--实例篇21页
- Oracle存储过程实例5页
- oracle存储过程实例34页
- oracle存储过程实例34页
- oracle+存储过程实例3页
- 存储过程语法及实例14页


