文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > 存储过程分页
侵权投诉

存储过程分页



====================================================================================================================
第一步:存储过程

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

第1页

你可能喜欢

  • Java笔记
  • oracle存储过程
  • mysql存储过程
  • 存储过程写法
  • 存储过程教程
  • 存储过程实例
  • 存储过程语法

热门文档

相关文档

  • 分页存储过程

    --TOP n 实现的通用分页存储过程(邹建) CREATE PROC sp_PageView @tbname sysname, --要分页显示的表名 @FieldKey nvarchar(1000), --用于定位记录的主键(...

  • SQL存储过程实现快速分页

    SQL存储过程实现快速分页_计算机软件及应用_IT/计算机_专业资料。二分法--/*---存储过程 分页处理 孙伟 2005-03-28创建 ---*/ --/*--- 对数据进行了2分...

  • SQL分页存储过程

    分页存储过程 /* QQ312430633 */ ALTER PROCEDURE [dbo].[les_AllowPaging] @pageindex int, ---***页码 @PageSize int, ---***每页显示条数 @tsql va...

  • SQL分页存储过程

    SQL分页存储过程_计算机软件及应用_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 SQL分页存储过程_计算机软件及应用_IT/计算机_专业资料。SQL分页存储...

  • sql分页存储过程

    解决分页功能 /*判断有无存储过程*/ IF OBJECT_ID('QueryCountrysDate','p')IS NOT NULL DROP PROCEDURE QueryCountrysData; GO /*创建存储过程*/ CREATE ...

  • 通用存储过程分页(top max模式)

    --/*---存储过程 分页处理 孙伟 2005-03-28创建 ---*/ --/*--- 对数据进行了2分处理使查询前半部分数据与查询后半部分数据性能相同 ---*/ --/*--...

  • C# 存储过程分页

    /**/// /// 返回FavList集合,使用存储过程自定义分页。 /// /// 数据库FavList的字段,用户ID /// 查找的条件 /// 排序,true表示Desc,false表示asc /...

  • 存储过程(分页显示)

    存储过程(分页显示)_专业资料。很值得一看20.PL/SQL分页编写分页过程 介绍?? 分页是任何一个网站(bbs,网上商城,blog)都会使用到的技术,因此学习pl/sql 编程开发...

  • 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...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email