假设每一页显示的数据条数为PageSize,当前页数(从0开始技术)为CurrentIndex,那么只要查询从第PageSize*CurrentIndex开始的PageSize条数据得到的结果就是当前页中的数据。
int CurrentIndex=0;
PageSize=10;
//按钮【首页】被点击
private void btnFirstButtonClick()
{
CurrentIndex=0;
DoSearch();
}
//按钮【尾页】被点击
private void btnLastButtonClick()
{
CurrentIndex=GetTotalCount()/PageSize;
DoSearch();
}
//按钮【下一页】被点击
private void btnNextButtonClick()
{
CurrentIndex=CurrentIndex+1;
DoSearch();
}
按钮【上一页】被点击
private void btnNextButtonClick()
{
CurrentIndex=CurrentIndex-1;
DoSearch();
}
//计算表中的总数据条数
private int GetToatalCount()
{
ResultSet rs = ExecuteSQL("SELECT COUNT(*) AS TOTALCOUNT FROM T_Employee");
return rs.getInt("TOTALCOUNT");
}
//查询当前页中的数据
private void DoSearch(0
{
//计算当前页的起始行数
String startIndex=(CurrentIndex *PageSize).ToString();
String size = PageSize.ToString();
ResultSet rs=ExecuteSQL("SELECT * FROM T_Employee LIMIT" +startIndex+","size);
//显示查询结果
DisplayResult(rs);
} |