c# winform 實現分頁查詢
效果如下
程式碼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
int n = 1;
int size = 1;
private void Form2_Load(object sender, EventArgs e)
{
this.label1.Text = “當前第”+n.ToString()+“頁”;
Getdata();
}
public void Getdata()
{
size =Convert.ToInt32(this.textBox1.Text);
string sql = “select from(select ,rn=ROW_NUMBER()over(order by id asc)from department )as t where t.rn between(@n-1)@size+1 and @n@size”;
SqlParameter[] pr = new SqlParameter[]
{
new SqlParameter("@n", SqlDbType.Int) {Value=n },
new SqlParameter("@size",SqlDbType.Int) { Value=size}
};
DataTable dt = DbHelper.GetDt(sql,pr);
this.dataGridView1.DataSource = dt;
}
private void button1_Click(object sender, EventArgs e)
{
if(n==1)
{
MessageBox.Show("已經是第一頁了");
}
else
{
n--;
this.label1.Text = "當前第" + n.ToString() + "頁";
Getdata();
}
}
private void button2_Click(object sender, EventArgs e)
{
string sql = "select count(*)from department";
int i = (int)DbHelper.ExecuteScalar(sql);
//總條數/每頁個數=總頁數
float x = i % size == 0 ?i/size : i % size + 1;
if(x==n||size>i)
{
MessageBox.Show("這是最後一頁了");
}
else
{
n++;
this.label1.Text = "當前第" + n.ToString() + "頁";
Getdata();
}
}
private void textBox1_MouseHover(object sender, EventArgs e)
{
n = 1;
size = Convert.ToInt32(this.textBox1.Text);
Getdata();
}
//private void textBox1_MouseMove(object sender, MouseEventArgs e)
//{
// n = 1;
// Getdata();
//}
//private void textBox1_ModifiedChanged(object sender, EventArgs e)
//{
// n = 1;
// Getdata();
//}
}
}
相關文章
- C# Winform ComboBox模糊查詢實現C#ORM
- indexdb實現分頁查詢Index
- SSM框架實現分頁查詢例子SSM框架
- MYSQL SQLServer分頁查詢的實現MySqlServer
- 如何優雅地實現分頁查詢
- Hibernate實現分頁查詢的原理
- SSH整合實現分頁查詢(兩種方式)
- 老聲常談,分頁查詢的實現就是不分頁
- golang通過mysql語句實現分頁查詢GolangMySql
- golang透過mysql語句實現分頁查詢GolangMySql
- SpringMVC+Spring Data JPA +Bootstrap 分頁實現和模糊查詢分頁SpringMVCboot
- Elasticsearch 分頁查詢Elasticsearch
- ssh 分頁查詢
- oracle分頁查詢Oracle
- MySQL的分頁查詢MySql
- ThinkPhp框架:分頁查詢PHP框架
- 分頁查詢優化優化
- NET 集合分頁查詢
- MySQL 多表查詢分頁MySql
- 分頁查詢重構
- Oracle的分頁查詢Oracle
- Oracle分頁查詢格式Oracle
- Lucene的分頁查詢
- PHP 實現二分查詢PHP
- elasticsearch查詢之大資料集分頁查詢Elasticsearch大資料
- MaxCompute如何對SQL查詢結果實現分頁獲取SQL
- JSP怎樣將查詢的資料實現分頁操作JS
- 實現分頁顯示資料[並按關鍵字查詢]
- WebView實現頁內文字查詢功能WebView
- 分庫分表後的分頁查詢
- IP地址查詢API的C#實現APIC#
- C#實現二叉查詢樹C#
- AntDesignBlazor示例——分頁查詢Blazor
- MySQL分頁查詢優化MySql優化
- Oracle分頁查詢格式(十三)Oracle
- Oracle分頁查詢格式(十二)Oracle
- Oracle分頁查詢格式(十一)Oracle
- Oracle分頁查詢格式(八)Oracle