public DataTable QueryDataTable(string queryStr)
{
DataTable dt = new DataTable();
OleDbConnection conn = new OleDbConnection(ConnectionString);
OleDbDataAdapter adp = new OleDbDataAdapter(queryStr, conn);
conn.Open();
adp.Fill(dt);
conn.Close();
return dt;
}
// 方法体的部分内容
DBCommon db = new DBCommon();
DataTable dt = new DataTable();
OleDbConnection conn = new OleDbConnection(db.ConnectionString);
OleDbCommand cmd = new OleDbCommand(countSql, conn);//查询数据总数,用于分页
OleDbDataAdapter adp = new OleDbDataAdapter(sqlStr, conn);
conn.Open();
var rs = cmd.ExecuteScalar().ToString();//解决直接强制转换为int时出错的问题。
count = Int32.Parse(rs);
adp.Fill(PageSize * (PageIndex - 1), PageSize, dt);
conn.Close();
创建OleDbCommand对象,用OleDbCommand对象执行SQL语句。