vs2005中,原来我是这样用的aspnetpager,这样也能用,使用access数据库
protected void Page_Load(object sender, EventArgs e)
{
conn = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + this.Server.MapPath( "App_Data/NWIND.mdb "));
if (!Page.IsPostBack)
{
cmd = new OleDbCommand( "select count(EmployeeID) from Employees ", conn);
conn.Open();
pager.RecordCount = (int)cmd.ExecuteScalar();
conn.Close();
BindData();
}
}
void BindData()
{
cmd = new OleDbCommand( "select EmployeeID,LastName,FirstName from Employees ", conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds, pager.PageSize * (pager.CurrentPageIndex - 1), pager.PageSize, "Employees ");
GridView1.DataSource = ds.Tables[ "Employees "];
GridView1.DataBind();
pager.CustomInfoText = "记录总数: <font color=\ "blue\ "> <b> " + pager.RecordCount.ToString() + " </b> </font> ";
pager.CustomInfoText += " 总页数: <font color=\ "blue\ "> <b> " + pager.PageCount.ToString() + " </b> </font> ";
pager.CustomInfoText += " 当前页: <font color=\ "red\ "> <b> " + pager.CurrentPageIndex.ToString() + " </b> </font> ";
}
但现在我用vs2005的强类型的生成的数据集
emploeesDataSet2TableAdapters.EmployeesTableAdapter ta = new emploeesDataSet2TableAdapters.EmployeesTableAdapter();
ta有ta.ScalarQuery()这样方法得到总记录数,
也有ta.GetData()得到整个数据集。
但我不知如何编写BindData()函数了。
主要是这几句如何改成用ta.GetData()就方便了。主要是ta.GetData()是得到所有数据,没有过滤掉不显示的数据。全部都显示出来了。
cmd = new OleDbCommand( "select EmployeeID,LastName,FirstName from Employees ", conn);