sql server 数据分页显示。

Posted 金桂花季

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 #tempRCUDCalc
20  from Financial.ReagentConsumablesUseDetailCalc
21  where StockApplyCode = @StockApplyCode
22 
23 declare @TotalRowCount INT   -- 总行数
24 SET @TotalRowCount  = (select COUNT(1) FROM #tempRCUDCalc)  
25 
26  declare @temp int
27  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 TotalRowCount
48  from #tempRCUDCalc A
49  where NOT EXISTS (
50     SELECT 1 from ( select top (select @temp) id from #tempRCUDCalc ORDER BY id) B where A.id = B.id
51  )
52  order by id
53  
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 数据分页显示。的主要内容,如果未能解决你的问题,请参考以下文章

缺少 SQL SERVER 2014 代码片段

springmvc 分页查询的简单实现

SQL server2005上千万条数据分页查询怎么做优化?

我们如何使用 Flask 对 SQL Server 搜索结果进行分页

存储过程sql server中的分页

Microsoft SQL Server 代码片段收集