C# 调用带有输出参数的分页存储过程
一、创建带有输出参数的分页存储过程
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# 调用带有输出参数的分页存储过程的更多相关文章
- sql server 带输入输出参数的分页存储过程(效率最高)
create procedure proc_page_withtopmax( @pageIndex int,--页索引 @pageSize int,--每页显示数 @pageCount int out ...
- java Servlet+mysql 调用带有输入参数和返回值的存储过程(原创)
这个数据访问的功能,我在.NET+Mysql .NET+Sqlserver PHP+Mysql上都实现过,并且都发布在了我博客园里面,因为我觉得这个功能实在是太重要,会让你少写很多SQL语句不说,还 ...
- Hibernate调用带有输入参数,输出参数为cursor的存储过程
一.Oracle创建表及存储过程 1.创建表T_MONITOR_DEVICE 创建后的表结构 2.创建存储过程 create or replace procedure ProcTestNew(v_mo ...
- C# 调用带输入输出参数的存储过程
//调用存储过程执行类似于2//select count(*) from userinfo where username=username and pwd=pwd and grade=grade3// ...
- c#调用带输出参数的存储过程
sql server中编写一个存储过程: CREATE PROCEDURE ProGetPWD @username varchar(20), @password varchar(20) OUTPUT ...
- php PDO调用带有out参数的存储过程(原创)
这几天比较闲学了下PHP, 开发工具zendphp,server下的一个集成工具WampServer. 感觉php实现一个功能写的代码比asp.net java都少,特别是数据库访问这块,如果是asp ...
- c#调用带有自定义表结构的存储过程
1.新建自定义表结构 CREATE TYPE [dbo].[HBForHBGHDR] AS TABLE( [序号] [int] NULL, [客户编号] [varchar](15) NULL ) GO ...
- 【Mybatis】MyBatis调用带有返回结果、output参数的存储过程上与ibatis的区别
用过mybatis的应该都知道它是ibatis被Google收购后重新命名的一个工程,因此也做了大量升级.本文就来介绍下两者在调用存储过程上的一点区别,ibatis有一个专门的标签<proced ...
- 创建有输出参数的存储过程并在c#中实现DataGridView分页功能
不足之处,欢迎指正! 创建有输出参数的存储过程 if exists(select * from sysobjects where name='usp_getPage1') drop procedure ...
随机推荐
- tmux还有这种操作,我在这边的窗口上操作,你那边可以实时的看到我的操作,厉害了
- 在head里的CSS link 竟然粗如今body里了?
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcGVhY2Vfb2Zfc291bA==/font/5a6L5L2T/fontsize/400/fill/I0 ...
- 【iOS开发-74】解决方式:Xcode6下利用preference保存数据,终于的plist文件在哪里?
(1)现象:普通情况下.储存数据以一个沙盒为单位,preference数据存在在沙盒路径下Library/Preferences里面,可是Xcode6里找来找去根本什么都没有. watermark/2 ...
- Cocos2d-X中的ProgressTimer
ProgressTimer即进度条,进度条在游戏开发中运用很广泛,比如在一些格斗游戏中,显示血液的变化,还有游戏载入进度,等都离不开进度条 Cocos2d-X中使用CCProgressTimer ...
- muduo源代码分析--Reactor模式在muduo中的使用
一. Reactor模式简单介绍 Reactor释义"反应堆",是一种事件驱动机制.和普通函数调用的不同之处在于:应用程序不是主动的调用某个API完毕处理.而是恰恰相反.React ...
- PAT Rational Arithmetic (20)
题目描写叙述 For two rational numbers, your task is to implement the basic arithmetics, that is, to calcul ...
- ibatis 取消查询动态列的缓存
ibatis在查询结果列不确定(或是动态变化)的情况下,会因为列缓存的原因导致变化后的列数据查不出来 解决方法是: select标签有个属性remapResults,该属性默认值为false,设置成r ...
- 解决vs2010无法找到System.Data.OracleClient的引用问题
解决vs2010无法找到System.Data.OracleClient的引用问题 2012-2-19 09:12| 发布者: benben| 查看: 7627| 评论: 0 摘要: 在vs201 ...
- 两个ajax写在一起报错
这样做完导致的结果是:在谷歌浏览器页面正常显示,在火狐浏览器会不定期出现系统异常错误提示!最后分析原因是: 从异步请求的执行原理来看,我们知道当一个异步请求发送时,浏览器不会处于锁死.等待的状态,从一 ...
- RDA 多屏参流程
一.RDA MAKEFILE的本地变量 在介绍多屏参之前,先看一下./code/env.conf的包含过程,通过./code/Makefile.project加载,env.conf中所有的变量,都变为 ...