System.Data.Common.DbDataAdapter.FillInternal C# (CSharp) Method

FillInternal() private method

private FillInternal ( DataSet dataset, DataTable datatables, int startRecord, int maxRecords, string srcTable, IDbCommand command, CommandBehavior behavior ) : int
dataset System.Data.DataSet
datatables System.Data.DataTable
startRecord int
maxRecords int
srcTable string
command IDbCommand
behavior CommandBehavior
return int
        private int FillInternal(DataSet dataset, DataTable[] datatables, int startRecord, int maxRecords, string srcTable, IDbCommand command, CommandBehavior behavior)
        {
            int rowsAddedToDataSet = 0;
            bool restoreNullConnection = (null == command.Connection);
            try
            {
                IDbConnection activeConnection = DbDataAdapter.GetConnection3(this, command, ADP.Fill);
                ConnectionState originalState = ConnectionState.Open;

                // the default is MissingSchemaAction.Add, the user must explicitly
                // set MisingSchemaAction.AddWithKey to get key information back in the dataset
                if (Data.MissingSchemaAction.AddWithKey == MissingSchemaAction)
                {
                    behavior |= CommandBehavior.KeyInfo;
                }

                try
                {
                    QuietOpen(activeConnection, out originalState);
                    behavior |= CommandBehavior.SequentialAccess;

                    IDataReader dataReader = null;
                    try
                    {
                        dataReader = command.ExecuteReader(behavior);

                        if (null != datatables)
                        { // delegate to next set of protected Fill methods
                            rowsAddedToDataSet = Fill(datatables, dataReader, startRecord, maxRecords);
                        }
                        else
                        {
                            rowsAddedToDataSet = Fill(dataset, srcTable, dataReader, startRecord, maxRecords);
                        }
                    }
                    finally
                    {
                        if (null != dataReader)
                        {
                            dataReader.Dispose();
                        }
                    }
                }
                finally
                {
                    QuietClose(activeConnection, originalState);
                }
            }
            finally
            {
                if (restoreNullConnection)
                {
                    command.Transaction = null;
                    command.Connection = null;
                }
            }
            return rowsAddedToDataSet;
        }