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

 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. oracle initialization or shutdown in progress 问题解决

    今天登录oracle时遇到oracle initialization or shutdown in progress 这个错误提示,在网上搜了下,试了非常多方法,最后结合几种方法结合,成功攻克了问题! ...

  2. 调试 Android* x86 应用程序的方法以及要使用的工具

    作者:Xiaodong Wang 1.简单介绍 众所周知,Android* 开发者头顶很多称呼:设计员.程序员等,而且一般会不可避免地被称为故障检修工. 代码中的错误无法避免.因此不管您是否一開始就造 ...

  3. ubuntu14.04 的ibus不能卸载(安装fcitx输入法框架时可能有这个需求)。出现无system setting有用程序

    每年的ubuntu新版本号公布,都会吸引一大批热血青年. 关注越多也让ubuntu越来越好了. 使用ubuntu的人都会在安装系统之后马上安装顺手的输入法,也可能不会.看人. 安装输入法,对于中文输入 ...

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

  5. firstChild.nodeValue

    var ia=document.getElementsByTagName("em");var t=600; for(var ii=0;ii<t;ii++){var it=ia ...

  6. 【转载pku】三十分钟掌握STL

    三十分钟掌握STL 这是本小人书.原名是<using stl>,不知道是谁写的.不过我倒觉得很有趣,所以化了两个晚上把它翻译出来.我没有对翻译出来的内容校验过.如果你没法在三十分钟内觉得有 ...

  7. Web安全总结摘录

    借助刚才看到的文章,回顾一下常见的Web安全问题:XSS.CSRF.SQL注入漏洞. 一.XSS XSS (Cross Site Script),跨站脚本攻击,因为缩写和 CSS (Cascading ...

  8. java笔记线程方式2

    方式2:实现Runnable接口 * 步骤: *   A:自定义类MyRunnable实现Runnable接口 *   B:重写run()方法 *   C:创建MyRunnable类的对象 *   D ...

  9. varnish的架构和日志

    varnish的架构和日志 varnish的架构 知道varnish的内部结构有两个重要的原因: 首先,架构主要负责性能,其次,它影响你如何将Varnish集成到你自己的架构中. 主程序块是Manag ...

  10. [App Store Connect帮助]四、添加 App 图标、App 预览和屏幕快照(5)移除 App 预览或屏幕快照

    您可以随时移除 App 预览,但仅可在 App 状态为可编辑时才能移除屏幕快照.要了解可编辑的状态,请前往 App 状态. 必要职能:“帐户持有人”职能.“管理”职能.“App 管理”职能或“营销”职 ...