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; }  
     }

    }



         这种方法能不能用到数据量相当大的表中?我想自己测,但没条件.
  • 相关阅读:
    C#中的Excel操作【1】——设置Excel单元格的内容,打开Excel文件的一种方式
    Java 在指定目录建立指定文件名的文件 并输入内容
    JSP基础——属性保存范围和request对象
    JSP基础总结(运行机制、脚本元素、指令元素、动作元素)
    weblogic 清除缓存
    oracle 分区表详解
    ORA-00257: archiver error的解决方法
    oracle中job定时器任务
    timestamp类型在jsp页面输出格式化方法
    cmd中测试常用到的命令汇总
  • 原文地址:https://www.cnblogs.com/ajiebp1977/p/460027.html
Copyright © 2011-2022 走看看