我正在使用此功能使用分页在 datagridview 中显示数据,使用此功能page 1
我可以正确显示最后 10 行,但是当我单击下一个按钮时它应该显示next last 10 rows
但它在每个下一页上显示前 10 行,我认为它们是我的错误,cmd2 query of else part
但那是什么?我正在使用 Access 数据库
private DataTable GetCurrentRecords(int page, OleDbConnection con)
{
dt = new DataTable();
if (page == 1)
{
cmd2 = new OleDbCommand("Select TOP " + PageSize + " QID,Question,Opt1,Opt2,Opt3,Opt4,AnsOp,Marks from Questions ORDER BY QID DESC", con);
// CurrentPageIndex++;
}
else
{
int PreviouspageLimit = (page - 1) * PageSize;
cmd2 = new OleDbCommand("Select TOP " + PageSize +
" QID,Question,Opt1,Opt2,Opt3,Opt4,AnsOp,Marks from Questions " +
"WHERE QID NOT IN " +
"(Select TOP " + PreviouspageLimit + " QID from Questions ORDER BY QID DESC) ", con); // +
//"order by MedicalClgID", con);
}
try
{
// con.Open();
this.adp1.SelectCommand = cmd2;
this.adp1.Fill(dt);
txtPaging.Text = string.Format("{0} of {1} ", this.CurrentPageIndex, this.TotalPage);
}
finally
{
// con.Close();
}
return dt;
}