往往我们开发各种信息系统的时候,不只是简单的从一个表读取数据,很可能是从多个表读取数据后,把结果展示在界面上,当遇到2个大表关联时,若技术上没进行一些处理,那分页显示时速度会非常糟糕,在通用权限管理系统组件了,有专门针对大数据的分页优化,下面的代码就是具体的实现方法。
#region private void DoSearch() 获取列表/// <summary>/// 获取列表/// </summary>private void DoSearch(){string searchValue = this.txtSearch.Text;// 总记录数量int recordCount = 0;BaseManager manager = new BaseManager(this.DbHelper, this.UserInfo, "KEYPROJECT");// 这个是需要显示的字段manager.SelectField = "ZPResumeInfo.ID, ZPResumeInfo.A0101, ZPResumeInfo_Remark.Remark";// 这个是2个表的关联manager.CurrentTableName = "ZPResumeInfo INNER JOIN ZPResumeInfo_Remark ON ZPResumeInfo.ID = ZPResumeInfo_Remark.ResumeID";// 这个是数据过滤条件string whereConditional = " ZPResumeInfo.CreUser = " + this.UserInfo.Id;// 这个是排序顺序string order = "ZPResumeInfo_Remark.ModifiedOn DESC";DataTable dataTable = manager.GetDataTableByPage(out recordCount, this.myNavigator.PageIndex + 1, this.myNavigator.PageSize, whereConditional, order);dataTable.DefaultView.Sort = this.SortExpression + " " + this.SortDire;// 绑定分页控件this.myNavigator.RowCount = recordCount;this.myNavigator.BindData(this.gridView, dataTable);// 按钮状态控制this.SetControlState();}#endregion
上面的例子代码就是从2个表里来的,大数据的分页显示效果参考,模仿上面的代码就可以制作你自己需要的数据了。