用复制数据源的方法,建一个临时DataTable,命名为tmpDataTable 分页加载如100行一页, tmpDataTable.Clear(); for (int i = 0; i < 100; i++) { tmpDataTable.Rows.Add(dt.Rows[i]); //dt是原来的数据源 } this.dataGridView1.DataSource = tmpDataTable;
SqlConnection con = new SqlConnection(constr); con.Open(); SqlDataAdapter sda = new SqlDataAdapter(selectsqlstr, con); ds = new DataSet(); sda.Fill(ds, i, j, tablename); //这一行就是了 dgv.DataSource = ds.Tables[tablename].DefaultView;偶是新手,前两天练习过。
//例如:每页20条记录, n表示页码 string strSql = string.Format("Select top 20 * from table where id not in (Select top {0} id from table)", n * 20);
分页加载如100行一页,
tmpDataTable.Clear();
for (int i = 0; i < 100; i++)
{
tmpDataTable.Rows.Add(dt.Rows[i]); //dt是原来的数据源
}
this.dataGridView1.DataSource = tmpDataTable;
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(selectsqlstr, con);
ds = new DataSet();
sda.Fill(ds, i, j, tablename); //这一行就是了
dgv.DataSource = ds.Tables[tablename].DefaultView;偶是新手,前两天练习过。
string strSql = string.Format("Select top 20 * from table where id not in (Select top {0} id from table)", n * 20);