关于DataAdapter 的int Fill(int startRecord, int maxRecords, params DataTable[] dataTables)方法

其实如果分页不需要很高很高的性能的话,完全可以使用
DataAdapter.Fill(int startRecord, int maxRecords, params DataTable[] dataTables)方法

原理是
while (0 < startRecord)
      
{
            
if (!container1.Read())
            
{
                  
return 0;
            }

            startRecord
--;
      }

      
int num1 = 0;
      
if (0 < maxRecords)
      
{
            
while ((num1 < maxRecords) && container1.Read())
            
{
                  
if (this._hasFillErrorHandler)
                  
{
                        
try
                        
{
                              mapping.LoadDataRowWithClear();
                              num1
++;
                        }

                        
catch (Exception exception1)
                        
{
                              
if (!ADP.IsCatchableExceptionType(exception1))
                              
{
                                    
throw;
                              }

                              ADP.TraceExceptionForCapture(exception1);
                              
this.OnFillErrorHandler(exception1, mapping.DataTable, mapping.DataValues);
                        }

                        
continue;
                  }

                  mapping.LoadDataRow();
                  num1
++;
            }

            
return num1;
      }

这个是 reflector出来的代码,我们可以看到,他使用datareader.Read到指定的行数。
按理来说,Read方法不怎么消耗时间。如果对访问速度要求不是极其苛刻的话,
这个方法完全是可以使用的。
这样不会导致返回的DataTable或者 DataSet太大。
其实,几千条的数据,应该也没有几个人会有耐心看完。

原文地址:https://www.cnblogs.com/wildfish/p/347804.html