以SQL Server2012提供的offset ..rows fetch next ..rows only为例

e.g.

表名:Tab1
----------------------------------
ID Name
1 tblAttributeGroupDetail
2 tblAttributeGroup
3 tblAttribute
.......
50 tblBRItemTypeAppliesTo
51 tblBRItemProperties
52 tblBRItem
53 tblBRBusinessRule
54 Test

--创建分页存储过程 rTabByCondition

USE [ExampleDB]
GO
if OBJECT_ID('rTabByCondition','P') is not null
drop procedure rTabByCondition
GO
create procedure [dbo].[rTabByCondition](
@PageCount int=1 --页数
,@PageSize int=10 --页显示记录数
,@Rowcount int=0 output --总记录数
)
as
set nocount on;
declare @Rows int;
select * from dbo.Tab1 order by ID offset (@PageCount-1)*@PageSize rows fetch next @PageSize rows only
set @Rows=@@ROWCOUNT
select @Rowcount=count(*) from dbo.Tab1;
return @Rows
go
declare @i int,@j int
exec @i=[rTabByCondition] @PageCount=6,@PageSize=10,@Rowcount=@j output
select @i as "@Rowcount",@j as "Return_Value"
go

显示结果:

--打开Visual Studio—创建项目—选择【控制台应用程序】

#region Directives
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
#endregion namespace SQLStoredProcedure2
{
class Program
{
static void Main(string[] args)
{
SqlConnection thisConnection = new SqlConnection(@"Server=(Local)\SQL16;Integrated Security=True;Database=ExampleDB");
thisConnection.Open();
SqlCommand thisCommend = thisConnection.CreateCommand();
thisCommend.CommandType = CommandType.StoredProcedure;
thisCommend.CommandText = "rTabByCondition";
thisCommend.Parameters.AddWithValue("@PageCount", "6");//页数
thisCommend.Parameters.AddWithValue("@PageSize", "10");//页显示记录数
SqlParameter paraOut = thisCommend.Parameters.Add("@Rowcount", SqlDbType.Int);//输出参数定义
paraOut.Direction = ParameterDirection.Output;
SqlParameter paraRet = thisCommend.Parameters.Add("return_value", SqlDbType.Int);//返回值
paraRet.Direction = ParameterDirection.ReturnValue;
SqlDataReader thisReader = thisCommend.ExecuteReader();
while (thisReader.Read())
{
Console.WriteLine("ID:{0}\tName:{1}", thisReader[0], thisReader[1]);
}
thisReader.Close();
thisConnection.Close();
Console.WriteLine("Rows:{0};\tReturn_Value:{1};", paraOut.Value, paraRet.Value);
Console.WriteLine("Program finished,press Enter/Return to continue:");
Console.ReadLine();
}
}
}

显示效果:

C#调用SQL Server分页存储过程的更多相关文章

  1. (转)jdbc 调用 sql server 的存储过程时“该语句没有返回结果集”的解决方法

    本文转载自:http://hedyn.iteye.com/blog/856040 在JDBC中调用SQL Server中的存储过程时出现如下异常: com.microsoft.sqlserver.jd ...

  2. Delphi 调用SQL Server 2008存储过程

    1.表结构如下(预算数据明细表): CREATE TABLE [dbo].[BA_FeeDetail]( [ID] [int] IDENTITY(1,1) NOT NULL, [FeeDeptID] ...

  3. Java调用SQL Server的存储过程详解

    转载自Microsoft的官方文档 http://msdn2.microsoft.com/zh-cn/library/ms378995.aspx收录于 www.enjoyjava.net/f25 本文 ...

  4. (转)Java调用SQL Server的存储过程详解

    本文转载自:http://dev.yesky.com/128/8088128.shtml 1使用不带参数的存储过程 使用 JDBC 驱动程序调用不带参数的存储过程时,必须使用 call SQL 转义序 ...

  5. Java调用SQL Server的存储过程详解(转)

    1使用不带参数的存储过程 使用 JDBC 驱动程序调用不带参数的存储过程时,必须使用 call SQL 转义序列.不带参数的 call 转义序列的语法如下所示: 以下是引用片段:{call proce ...

  6. 分页系列之一:SQL Server 分页存储过程

    以下为最基本的代码结构,SQL Server 2012 开始支持 CREATE PROCEDURE procXXX @Page int, --当前页码,从1开始 @PageSize int --每页记 ...

  7. sql server 分页存储过程

    ----------------------分页存储过程------------------------------------------------------------------------ ...

  8. [转]Sql Server 分页存储过程

    本文转自: 版权声明:作者:jiankunking 出处:http://blog.csdn.net/jiankunking  本文版权归作者和CSDN共有,欢迎转载,但未经作者同意必须保留此段声明,且 ...

  9. c++ builder调用sql server的存储过程进行数据的下载和上传

    小小的几行代码,在这里搞了一天.好好的一个周六过的无比的难受.代码很简单,但是主要原因是因为在用合作商的软件上传数据的时候有些框框没有勾选. come on....... 1.用两个控件ADOConn ...

随机推荐

  1. Nam Game

    哪一方最终给对方留下4的倍数个石头则win,即想方设法的给对方留下4的倍数个石头. 例如: 9(B win) A:3 B:2(B取2,给对方余4,对方则lose) A:1 | 2 | 3 B:3 | ...

  2. hdu-1213-How Many Tables

    How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  3. python-ldap实现登录案例

    ldap_config = { 'ldap_path': 'ldap://xx.xx.xx.xx:389', 'base_dn': 'ou=users,dc=ledo,dc=com', 'ldap_u ...

  4. <welcome-file-list>标签的控制作用以及在springmvc中此标签的的配置方式

    我们在写安全性较高的网站时必然会对网站的入口进行限制, 而在这其中其关键作用的就是网站的根目录下WEB-INF中的web.xml中<welcome-file-list>  <welc ...

  5. Guava学习笔记:简化异常处理的Throwables类

    有时候, 当我们我们捕获异常, 并且像把这个异常传递到下一个try/catch块中.Guava提供了一个异常处理工具类, 可以简单地捕获和重新抛出多个异常.例如: import java.io.IOE ...

  6. 1 UML基础

    学习设计模式的过程中,发现相关的作者们都会用UML类图来表示一个模式的整体脉络,这种方式确实直观明了,既能体现宏观思路.又能兼顾实现细节.真的是很妙的工具.在开始正式学习设计模式之前,有必要对UML有 ...

  7. Ext.Net MVC 配置(1)

    1.在VS2012中创建MVC3项目 2.在项目总启动NuGet,在里面安装Ext.net 3.安装Ext.net 4.安装完成后项目中相关的配置文件就会有所改变了. 5.测试:运行mvc项目:htt ...

  8. Xamarin安装和跳坑指南

    安装Checklist 注意:本文只描述安装过程,由于组件的版本更新很快,为保证文章时效性,不提供下载链接,也尽可能不指明具体版本. 安装Visual Studio 2015进行默认安装,除非已经FQ ...

  9. C#实现jQuery的方法连缀

    jQuery的方法连缀使用起来非常方便,可以简化语句,让代码变得清晰简洁.那C#的类方法能不能也实现类似的功能呢?基于这样的疑惑,研究了一下jQuery的源代码,发现就是需要方法连缀的函数方法最后返回 ...

  10. 使用 WordPress 主题制作的20个精美网页

    WordPress 是一款个人博客系统,并逐步演化成一款内容管理系统软件,它是使用 PHP 语言和 MySQL 数据库开发的.用户可以在支持 PHP 和 MySQL 数据库的服务器上使用自己的博客.这 ...