一、创建带有输出参数的分页存储过程

 use StudentMISDB
go
select * from Course
alter table Course
add IsDelete int not null default 0
go
select * from Course where IsDelete=1 --update Course set IsDelete=0 ---循环 添加数据
--declare @index int
--set @index =0
--while(@index<2)
--begin
-- insert into Course select Name,ByName,IsDelete from Course
-- set @index=@index+1;
--end --分页 显示 第 11 到20条的数据 select * from(select ROW_NUMBER() over(order by courseId)as rowNUM, * from Course
where IsDelete=0)as temp
where rowNUM>=11 and rowNUM<=20 select count(1)as rowRount from Course where IsDelete=0 --pageIndex 从 0 开始
--pageSize 每页显示的数据条数【10 条】
--((pageIndex) *pageSize)+1 (pageIndex * pageSize)+pageSize
--11 20 --总页数 pageCount = 总的记录/pageSize
---分页的 要素:1.当前 页码 pageIndex
--2. 每一页的 容量 pageSize
--3. 总条数 count
--4. 总页数 pageCount=count/pageSize --创建分页的存储过程
create proc Proc_GetPageData
@pageIndex int,
@pageSize int,
@rowCount int out,
@pageCount int out
as
begin
select * from(select ROW_NUMBER() over(order by courseId)as rowNUM, * from Course where IsDelete=0)as temp
where rowNUM>(@pageIndex*@pageSize) and rowNUM<= (@pageIndex*@pageSize+@pageSize) select @rowCount =count(1) from Course where IsDelete=0
set @pageCount=@rowCount/@pageSize
end
go declare @pageIndex int,
@pageSize int,
@rowCount int,
@pageCount int --select @pageIndex=3,@pageSize=10
exec Proc_GetPageData @pageIndex,@pageSize,@rowCount out,@pageCount out
--select @rowCount,@pageCount select * from Students
go

二、在C#中对存储过程进行调用,并且进行参数化和断开式连接查询,并利用DataGridView插件将结果显示在窗体中.

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient; namespace Demo01
{
public partial class UseSaveProcess : Form
{
public UseSaveProcess()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
//数据库连接字符
string connstring = "server=.;database=StudentMISDB;uid=sa;pwd=123456";
//连接数据库
SqlConnection conn = new SqlConnection(connstring);
//调用存储过程
string sql = "Proc_GetPageData";
//定义参数
SqlParameter[] parameter = new SqlParameter[] {
new SqlParameter("@pageIndex",SqlDbType.Int),
new SqlParameter("@pageSize",SqlDbType.Int),
new SqlParameter("@rowCount",SqlDbType.Int),
new SqlParameter("@pageCount",SqlDbType.Int)
};
//给参数赋值
parameter[].Value = ;
parameter[].Value = ;
//标明输出参数
parameter[].Direction = ParameterDirection.Output;
parameter[].Direction = ParameterDirection.Output;
//执行命令
SqlCommand cmd = new SqlCommand(sql,conn);
//声明SQL语句是存储过程
cmd.CommandType = CommandType.StoredProcedure;
//添加参数
cmd.Parameters.AddRange(parameter);
//断开式连接查询
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//建立数据集(缓冲区)
DataSet ds = new DataSet();
conn.Open();
adapter.Fill(ds);
conn.Close();
//绑定数据源
this.dataGridView1.DataSource = ds.Tables[];
//显示在下方的lable中
int rowcount = Convert.ToInt32(parameter[].Value);
int pagecoun = Convert.ToInt32(parameter[].Value);
this.label1.Text = "总共有" +rowcount+"条数据,共有" +pagecoun+"页";
}
}
}

C# 调用带有输出参数的分页存储过程的更多相关文章

  1. sql server 带输入输出参数的分页存储过程(效率最高)

    create procedure proc_page_withtopmax( @pageIndex int,--页索引 @pageSize int,--每页显示数 @pageCount int out ...

  2. java Servlet+mysql 调用带有输入参数和返回值的存储过程(原创)

    这个数据访问的功能,我在.NET+Mysql .NET+Sqlserver  PHP+Mysql上都实现过,并且都发布在了我博客园里面,因为我觉得这个功能实在是太重要,会让你少写很多SQL语句不说,还 ...

  3. Hibernate调用带有输入参数,输出参数为cursor的存储过程

    一.Oracle创建表及存储过程 1.创建表T_MONITOR_DEVICE 创建后的表结构 2.创建存储过程 create or replace procedure ProcTestNew(v_mo ...

  4. C# 调用带输入输出参数的存储过程

    //调用存储过程执行类似于2//select count(*) from userinfo where username=username and pwd=pwd and grade=grade3// ...

  5. c#调用带输出参数的存储过程

    sql server中编写一个存储过程: CREATE PROCEDURE ProGetPWD @username varchar(20), @password varchar(20) OUTPUT ...

  6. php PDO调用带有out参数的存储过程(原创)

    这几天比较闲学了下PHP, 开发工具zendphp,server下的一个集成工具WampServer. 感觉php实现一个功能写的代码比asp.net java都少,特别是数据库访问这块,如果是asp ...

  7. c#调用带有自定义表结构的存储过程

    1.新建自定义表结构 CREATE TYPE [dbo].[HBForHBGHDR] AS TABLE( [序号] [int] NULL, [客户编号] [varchar](15) NULL ) GO ...

  8. 【Mybatis】MyBatis调用带有返回结果、output参数的存储过程上与ibatis的区别

    用过mybatis的应该都知道它是ibatis被Google收购后重新命名的一个工程,因此也做了大量升级.本文就来介绍下两者在调用存储过程上的一点区别,ibatis有一个专门的标签<proced ...

  9. 创建有输出参数的存储过程并在c#中实现DataGridView分页功能

    不足之处,欢迎指正! 创建有输出参数的存储过程 if exists(select * from sysobjects where name='usp_getPage1') drop procedure ...

随机推荐

  1. centos7更新、更新、每天更新、每天自动更新

    每一天我们的系统时时刻刻都被凶狠之徒盯着,保持软件在最新的状态是其中一项我们必须做,也很容易做到的工作. 首先我们立即手动更新所有预先安装的软件: yum -y update 跟着设定系统定时自动更新 ...

  2. ubuntu语言设置成汉语

    打开设置system setting,进入语言支持,有语言和地区格式.下载须要的语言并应用到整个系统. 按说明来就可以 这样的方法使得部分英语变为汉语.

  3. Django打造大型企业官网(五)

    4.6.切换轮播图的箭头样式以及显示和隐藏 templates/news/index.html <span class="arrow left-arrow">‹< ...

  4. cocos2dx 2.2.3编译第一个apk到安卓手机

    1.android-ndk-r10(注意32位和64位的别下错了 我不小心下错了 折腾了我两天) 2.adt_201407(eclipse已经跟sdk等等集成在一起了)   3.Cococs2d-x ...

  5. ImportError: No module named &#39;ConfigParser&#39;

    Resolve Method: I found the problem. I had manually installed a newer version of python (version 3.2 ...

  6. web 开发之js---js 实现地址栏的表单提交加密编码

    以前在做嵌入式web时,曾经想过cgi加密,原来js可以直接实现,太好了,这里js在客户端实现编码和解码 一.在地址栏直接输入:javascript:str=encodeURI("笃行天下& ...

  7. 【Espruino】NO.13 蓝牙模块

    http://blog.csdn.net/qwert1213131/article/details/31830809 本文属于个人理解,能力有限.纰漏在所难免,还望指正! [小鱼有点电] [Espru ...

  8. Html.RenderPartial使用三个参数

    Html.RenderPartial("usercontrolurl", model, ViewDataDictionary) 当使用三个参数时可以这样使用: var data = ...

  9. linux内核对块设备的使用

    1 partition table 这里的分析以经典的MBR为例. 在MBR里面有partition table,每一项对应一个逻辑的块设备,partion table中的每一项是16个字节. 第一个 ...

  10. linux用于文件解压缩的命令

    1 gzip gzip -<压缩率> 压缩率用数字(1-9)来表示,越大,则压缩率越大. 2 bz2 解压bz2 bzip2 -d filename.bz2