首页 > 代码库 > sql server 数据分页显示。

sql server 数据分页显示。

 1 select [ID] 2       ,[StockApplyCode] 3       ,[RcCode] 4       ,[LabCenterCode] 5       ,[LabGroupCode] 6       ,[LabGroupName] 7       ,[Barcode] 8       ,[TestSubItemCode] 9       ,[TestSubItemName]10       ,[CreateDate]11       ,[CalcRule]12       ,[BomType]13       ,[BomConsume]14       ,[SingleConsumePredict]15       ,[SingleConsume]16       ,[BeginDate]17       ,[EndDate]18       ,[CostPrice] 19  into #tempRCUDCalc20  from Financial.ReagentConsumablesUseDetailCalc21  where StockApplyCode = @StockApplyCode22 23 declare @TotalRowCount INT   -- 总行数24 SET @TotalRowCount  = (select COUNT(1) FROM #tempRCUDCalc)  25 26  declare @temp int27  set @temp=@PageSize*(@PageIndex - 1)28  select top (select @PageSize) 29        [ID]30       ,[StockApplyCode]31       ,[RcCode]32       ,[LabCenterCode]33       ,[LabGroupCode]34       ,[LabGroupName]35       ,[Barcode]36       ,[TestSubItemCode]37       ,[TestSubItemName]38       ,[CreateDate]39       ,[CalcRule]40       ,[BomType]41       ,[BomConsume]42       ,[SingleConsumePredict]43       ,[SingleConsume]44       ,[BeginDate]45       ,[EndDate]46       ,[CostPrice]47       --,@TotalRowCount TotalRowCount48  from #tempRCUDCalc A49  where NOT EXISTS (50     SELECT 1 from ( select top (select @temp) id from #tempRCUDCalc ORDER BY id) B where A.id = B.id51  )52  order by id53  54  --结果总行数55  select COUNT(1) TotalRowCount FROM #tempRCUDCalc
技术分享
public void LoadReagentConsumablesUseApplyEdit(string strApplyCode, int pageIndex, int pageSize, out int countTotal, out int allRowsCount)        {            countTotal = 1000;            allRowsCount = 0;            try            {                if (pageIndex <= 0)                    pageIndex = 1;                if (pageSize <= 0)                    pageSize = 1000;                Byte[] isData = ServiceExecuteMethod.ExecuteMethod<IFinancial>(Config.ReadValueByKey(CommonString.IFinancialUrl),                    "LoadReagentConsumablesUseApplyEditByPage", new object[] { strApplyCode, pageIndex, pageSize }, Config.ReadValueByKey(CommonString.IFinancialBinding)) as Byte[];                if (pageIndex == 1)                {                    _ReagentConsumablesUse = DataZipHelp.RetrieveDataSetDecompress(isData) as DSReagentConsumablesUse;                    countTotal = _ReagentConsumablesUse.ReagentConsumablesUseDetailCalc.Count;                    if (countTotal > 0)                        allRowsCount = int.Parse(_ReagentConsumablesUse.Tables["TableInfo"].Rows[0]["TotalRowCount"].ToString());                }                else                {                    DSReagentConsumablesUse dsTemp = DataZipHelp.RetrieveDataSetDecompress(isData) as DSReagentConsumablesUse;                    if (_ReagentConsumablesUse == null) return;                    countTotal = dsTemp.ReagentConsumablesUseDetailCalc.Count;                    if (countTotal > 0)                        allRowsCount = int.Parse(_ReagentConsumablesUse.Tables["TableInfo"].Rows[0]["TotalRowCount"].ToString());                    _ReagentConsumablesUse.ReagentConsumablesUseDetailCalc.Merge(dsTemp.ReagentConsumablesUseDetailCalc);                    _ReagentConsumablesUse.AcceptChanges();                }            }            catch (Exception ex)            {                throw ex;            }        }   private void RefreshReagentConsumablesUseDetailCalcData()        {            try            {                //弹出提示画面                  new Thread((ThreadStart)delegate                {                    WaitingDataRefreshing = new DevExpress.Utils.WaitDialogForm("请稍候...", "正在加载数据", new Size(300, 40));                    Application.Run(WaitingDataRefreshing);                }).Start();                _Biz.LoadReagentConsumablesUseApplyEdit(StockApplyCode, ++pageIndex, pageSize, out countTotal, out allRowsCount);                // TempDS = CommonBiz.SplitDataSet(_Biz.ReagentConsumablesUse, TempDS, "ReagentConsumablesUseDetailCalc", ++pageIndex, pageSize, out countTotal, out allRowsCount);                //申请明细-分摊                _BSReagentConsumablesUseDetailCalc.DataSource = _Biz.ReagentConsumablesUse;                _BSReagentConsumablesUseDetailCalc.DataMember = "ReagentConsumablesUseDetailCalc";                grdcReagentConsumablesUseDetailCalc.EmbeddedNavigator.TextStringFormat = @"Record {0} of " + allRowsCount.ToString();                grdvReagentConsumablesUseDetailCalc.BestFitColumns();                //waitDialogForm.Close();                WaitingDataRefreshing.Invoke((EventHandler)delegate { WaitingDataRefreshing.Close(); });            }            catch (Exception ex)            {                XtraMessageBox.Show("数据加载失败!错误信息[" + ex.Message + "]");            }        } private void GrdvReagentConsumablesUseDetailCalc_TopRowChanged(object sender, EventArgs e)        {            try            {                if (grdvReagentConsumablesUseDetailCalc.IsRowVisible(grdvReagentConsumablesUseDetailCalc.RowCount - 1) == RowVisibleState.Visible)                {                    grdvReagentConsumablesUseDetailCalc.TopRowChanged -= GrdvReagentConsumablesUseDetailCalc_TopRowChanged;                    if (countTotal == pageSize && allRowsCount > countTotal)                    {                        RefreshReagentConsumablesUseDetailCalcData();                        grdvReagentConsumablesUseDetailCalc.TopRowChanged += GrdvReagentConsumablesUseDetailCalc_TopRowChanged;                    }                }            }            catch (Exception ex)            {                XtraMessageBox.Show(ex.Message);            }        }
使用代码

 

sql server 数据分页显示。