由于ce3.0不支持TOP,所以分页采用以下方法比较好
//执行查询
DBConnPool pool = DBConnPool.Instance;
SqlCeConnection conn = null;
try
{
conn = pool.BorrowDBConn();
SqlCeDataAdapter da = null;
DataSet ds = new DataSet();
if (this.m_pageCount == 0)
{
da = new SqlCeDataAdapter(this.m_csql, conn);
da.Fill(ds, "totalRowCount");
this.m_totalRowCount = int.Parse(ds.Tables["totalRowCount"].Rows[0][0].ToString());
if (this.m_totalRowCount != 0 && this.m_totalRowCount % this.m_pageRowCont == 0)
{
this.m_pageCount = this.m_totalRowCount / this.m_pageRowCont;
}
else
{
this.m_pageCount = this.m_totalRowCount / this.m_pageRowCont + 1;
}
}
int startRecord = (this.m_currentPage - 1) * this.m_pageRowCont;
int maxRecords = this.m_currentPage * this.m_pageRowCont;
da = new SqlCeDataAdapter(this.m_sql, conn);
da.Fill(ds,startRecord,maxRecords,"table1");
this.caseDataGrid.DataSource = ds.Tables["table1"];
this.caseDataGrid.TableStyles.Clear();
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName ="table1";
this.caseDataGrid.TableStyles.Add(ts);
this.caseDataGrid.TableStyles["table1"].GridColumnStyles["ID"].Width = 0;
for (int m = 0; m < ts.GridColumnStyles.Count; m++)
{
ts.GridColumnStyles[m].NullText = "";
}
this.pageLabel.Text = this.m_currentPage + "/" + this.m_pageCount;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (conn != null)
{
pool.ReturnDBConn(conn);
}
}