// 执行分页获取记录数和页面数信息
OleDbDataAdapter adapter = new OleDbDataAdapter();
DataSet ds = new DataSet();
try
...{
// 统计总记录数, 得出记录总和页面数
adapter.SelectCommand = new OleDbCommand(sqlCount, conn);
adapter.Fill(ds, "Count");
recordCount = (int)(ds.Tables["count"].Rows[0])["RowCount"];
ds.Clear();
pageCount = recordCount / pageSize + (recordCount % pageSize > 0 ? 1 : 0);
}
catch (Exception e)
...{
errorMessage = e.Message;
return false;
}
finally
...{
conn.Close();
}
isDirty = false;
return true;
}
// 执行分页查询
public DataTable GetData(int page)
...{
errorMessage = "";
if (isDirty)
...{
errorMessage = "查询条件已改变,必须先执行分页才能再次读取数据";
return null;
}
// 开始查询
OleDbConnection conn = new OleDbConnection(connectionString);
try
...{
conn.Open();
}
catch (Exception e)
...{
errorMessage = e.Message;
return null;
}
// 执行分页并读取数据
OleDbDataAdapter adapter = new OleDbDataAdapter();
DataSet ds = new DataSet();
try
...{
// 执行分页并读取数据
if (page > pageCount)
...{
errorMessage = "页面数溢出!";
return null;
}
int recordStartIndex = (page - 1) * pageSize;
adapter.SelectCommand = new OleDbCommand(this.SelectCommand, conn);
adapter.Fill(ds, recordStartIndex, pageSize, table);
}
catch (Exception e)
...{
errorMessage = e.Message;
return null;
}
finally
...{
conn.Close();
}
return ds.Tables[table];
}
}
}

