====================================================================================================================
第一步:存储过程
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
--TOP n 实现的通用分页存储过程(邹建) CREATE PROC sp_PageView @tbname sysname, --要分页显示的表名 @FieldKey nvarchar(1000), --用于定位记录的主键(...
SQL存储过程实现快速分页_计算机软件及应用_IT/计算机_专业资料。二分法--/*---存储过程 分页处理 孙伟 2005-03-28创建 ---*/ --/*--- 对数据进行了2分...
分页存储过程 /* QQ312430633 */ ALTER PROCEDURE [dbo].[les_AllowPaging] @pageindex int, ---***页码 @PageSize int, ---***每页显示条数 @tsql va...
SQL分页存储过程_计算机软件及应用_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 SQL分页存储过程_计算机软件及应用_IT/计算机_专业资料。SQL分页存储...
解决分页功能 /*判断有无存储过程*/ IF OBJECT_ID('QueryCountrysDate','p')IS NOT NULL DROP PROCEDURE QueryCountrysData; GO /*创建存储过程*/ CREATE ...
--/*---存储过程 分页处理 孙伟 2005-03-28创建 ---*/ --/*--- 对数据进行了2分处理使查询前半部分数据与查询后半部分数据性能相同 ---*/ --/*--...
/**/// /// 返回FavList集合,使用存储过程自定义分页。 /// /// 数据库FavList的字段,用户ID /// 查找的条件 /// 排序,true表示Desc,false表示asc /...
存储过程(分页显示)_专业资料。很值得一看20.PL/SQL分页编写分页过程 介绍?? 分页是任何一个网站(bbs,网上商城,blog)都会使用到的技术,因此学习pl/sql 编程开发...
Sql分页存储过程Sql分页存储过程隐藏>> SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO ALTER PROCEDURE aspNetPage ( @tblName nvarchar(200), ---要显示...
数据库—分页存储过程_计算机软件及应用_IT/计算机_专业资料。数据库—分页存储过程USE [TSMS] GO /*** Object: StoredProcedure [dbo].[Pager_ConditionProSearch...
热门文档