zoukankan      html  css  js  c++  java
  • Duwamish这种分页方式的效率

         Duwamish是VS2003下带的的例子,其中,自定义分页是这样实现的:

       
    public ProductResults[] GetList(string catid, int currentPage, int pageSize, ref int numResults) 
    {
     numResults 
    = 0;
     
    int index=0;
     SqlDataReader reader 
    = GetList(catid);
     ProductResults[] results 
    = new ProductResults[pageSize];
     
     
    // now loop through the list and pull out items of the specified page
     int start = (int)((currentPage - 1* pageSize);
     
    if (start <= 0) start = 1;

     
    // skip 
     for (int i = 0; i < start - 1; i++{
      
    if (reader.Read()) numResults++;
     }

     
    if (start > 1) reader.Read();

     
    // read the data we are interested in
     while (reader.Read()) {
      
    if (index < pageSize) {
       results[index] 
    = new ProductResults();
       results[index].productid 
    = reader.GetString(0);
       results[index].name 
    =  reader.GetString(1);
       index
    ++;
      }

      numResults
    ++;   
     }


     reader.Close();

     
    // see if need to redim array
     if (index == pageSize)
      
    return results;
     
    else {
      
    // not a full page, redim array
      ProductResults[] results2 = new ProductResults[index];
      Array.Copy(results, results2, index);
      
    return results2;
     }
        
    }



       

            数据分页通过currentPage和pageSize,只返回满足需要的最少的数据量,而不是将整个DataTable一股脑的绑定到DataGrid。在这里,数据被真正的读出来,并且被手动填充到一个自定义的对象数组中。

           ProduceResults的定义:
           

    public class ProductResults 
    {
     
    private string m_productid;
     
    private string m_name;

     
    // product props
     public string productid {
      
    get return m_productid; }
      
    set { m_productid = value; }  
     }


     
    public string name {
      
    get return m_name; }
      
    set { m_name = value; }  
     }

    }



         这种方法能不能用到数据量相当大的表中?我想自己测,但没条件.
  • 相关阅读:
    文件夹选项查看显示所有文件和文件夹..确定后隐藏文件依然不能显示,.
    加速电脑启动,给电脑瘦身
    进行性肌营养不良症的治疗
    可变量程的直流电压表
    数字图象处理课件 下载
    两顾高楼
    技巧心得:给拥有Google AdSense 帐户 朋友的一点忠告
    进行性肌营养不良研究又有新的发现
    电子通讯系统 >> BAS系统在地铁环境控制中的应用及实现
    J2ME游戏开发中时钟的简单实现
  • 原文地址:https://www.cnblogs.com/ajiebp1977/p/460027.html
Copyright © 2011-2022 走看看