我一直使用DataAdapter.Fill方法,比如:OleDbDataAdapter.Fill(dataset1,0,10,"table1")这种方法来进行分页,
但是我也一直不清楚Fill方法到底和数据库怎么交互的.比如数据库里有100条记录,而OleDbDataAdapter.Fill(dataset1,0,10,"table1")会取得10条记录
那么:
OleDbDataAdapter是从数据库取得100条记录,然后从中选10条记录给DataSet呢?
还是数据库只返回了10条记录给OleDbDataAdapter?
请高手指点,顺便请教此类问题应该去哪里搜索?MSDN上找了下,没有找到.我一直认为是后者,这样用我的分页方法,性能就会高一些.
如果是前者,那么我也就没必要自己分页那么辛苦了,直接用控件的分页功能就好了.

解决方案 »

  1.   

    从数据库取得100条记录,然后选10条记录给DataSet的。您如果有兴趣的话,可以看看DBDataAdapter的源代码。private int FillInternal(DataSet dataset, DataTable[] datatables, int startRecord, int maxRecords, string srcTable, IDbCommand command, CommandBehavior behavior)
    {
        bool flag = null == command.Connection;
        try
        {
            IDbConnection connection = GetConnection3(this, command, "Fill");
            ConnectionState open = ConnectionState.Open;
            if (MissingSchemaAction.AddWithKey == base.MissingSchemaAction)
            {
                behavior |= CommandBehavior.KeyInfo;
            }
            try
            {
                QuietOpen(connection, out open);
                behavior |= CommandBehavior.SequentialAccess;
                using (IDataReader reader = null)
                {
                    reader = command.ExecuteReader(behavior);
                    if (datatables != null)
                    {
                        return this.Fill(datatables, reader, startRecord, maxRecords);
                    }
                    return this.Fill(dataset, srcTable, reader, startRecord, maxRecords);
                }
            }
            finally
            {
                QuietClose(connection, open);
            }
        }
        finally
        {
            if (flag)
            {
                command.Transaction = null;
                command.Connection = null;
            }
        }
        return 0;
    }
      

  2.   

    那也就是说:OleDbDataAdapter.Fill取得指定记录,和GridView的自动分页功能,
    其效率是一样的了?如果我要的结果是让数据库返回10条记录,那么只能自己在SQL里想办法了?
    类似:select top 10 * from table这样子?