用存储过程给DataGridView分页入门
来源:互联网 发布:爱国者淘宝店铺名字 编辑:程序博客网 时间:2024/05/16 06:09
存储过程
CREATE PROCEDURE dbo.pagination ( @PageSize int = 10, @CurrentPageIndex int=1 ) AS declare @index int if(@CurrentPageIndex=1) begin EXEC( 'SELECT TOP ' + @PageSize + '* from Orders ') end else begin set @index= (@CurrentPageIndex-1) * @PageSize EXEC( 'SELECT TOP ' + @PageSize + '* from Orders where OrderId not in ' +'(select top '+ @index +'OrderId from Orders ) ') end RETURN
实现分页
private const int pageSize = 10; DataTable dtInfo = null; protected string ConnectStr() { string _connnectionStr = String.Format("Data Source=localhost;AttachDbFilename={0};Integrated Security=True", @"F:\xyt\MyProject\DataGridView\DataGridViewAndCheckBox\DataGridViewAndCheckBox\bin\Debug\b2bdb_Data.MDF");//连接字符串 return _connnectionStr; } private DataTable LoadData(int PageIndex) { SqlConnection con = new SqlConnection(this.ConnectStr()); SqlCommand cmd = new SqlCommand("pagination", con); cmd.CommandType = CommandType.StoredProcedure; con.Open(); cmd.Parameters.Add(new SqlParameter("@PageSize", SqlDbType.Int, 4)); cmd.Parameters["@PageSize"].Value =pageSize; cmd.Parameters.Add(new SqlParameter("@CurrentPageIndex", SqlDbType.Int, 4)); cmd.Parameters["@CurrentPageIndex"].Value = PageIndex; DataTable dt = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(dt); con.Close(); return dt; } private void Form1_Load(object sender, EventArgs e) { dtInfo = LoadData(1); this.dataGridView1.DataSource = dtInfo; this.label1.Text = Convert.ToString(1); } private void btnNext_Click(object sender, EventArgs e) { this.label1.Text = (Convert.ToInt32(this.label1.Text) + 1).ToString(); dtInfo = LoadData(Convert.ToInt32(this.label1.Text)); if (dtInfo.Rows.Count==0)//已经是最后一页 { this.label1.Text = (Convert.ToInt32(this.label1.Text) - 1).ToString(); MessageBox.Show("已经是最后一页!"); } else { this.dataGridView1.DataSource = null; this.dataGridView1.DataSource = dtInfo; } } private void btnPrevious_Click(object sender, EventArgs e) { if (this.label1.Text=="1") { MessageBox.Show("已经是第一页!"); return; } else { this.label1.Text = (Convert.ToInt32(this.label1.Text) - 1).ToString(); dtInfo = LoadData(Convert.ToInt32(this.label1.Text)); this.dataGridView1.DataSource = null; this.dataGridView1.DataSource = dtInfo; } }
- 用存储过程给DataGridView分页入门
- 一个DataGridView的分页代码(用存储过程来实现)
- C# DataGridView分页功能(SQL分页存储过程实现)
- C#-DataGridView分页功能的实现(存储过程实现)
- C#-DataGridView分页功能的实现(存储过程实现)
- 存储过程示例---用存储过程分页
- 用存储过程实现分页
- 用存储过程实现分页
- 利用SQL存储过程给SqlDataReader数据分页
- 关于数据库存储过程分页DatagridView BindingNavigator 控件的详细实现 winform
- orcale分页 存储过程分页
- 一个用存储过程的基本分页。
- 用存储过程实现的分页程序
- asp 用存储过程实现数据分页
- asp用存储过程实现快速分页
- 用存储过程实现的分页程序
- 用存储过程实现的分页程序
- 用存储过程实现的分页程序
- TMOD TCON SCON
- Linux 2.6.19.x 内核编译配置
- 随机概率发生器
- 敏捷
- 如何彻底删除91助手
- 用存储过程给DataGridView分页入门
- 多线程控制方法
- 实现strrev()函数
- TI Davinci DM6446开发攻略——UBL移植
- Campass指南针绘制
- 记录学习的点滴
- 面试中问的话题Spring工作原理
- Android 位于底部的Tab
- 归并排序(merge sort)——数据结构与算法复习