public DisconnectedReader(IDataReader reader)
{
// Cache field information
this.fields = new FieldInfo[reader.FieldCount];
this.ordinals = new Hashtable(StringComparer.OrdinalIgnoreCase);
for (int index = 0; index < fields.Length; index++)
{
FieldInfo field = new FieldInfo();
field.Name = reader.GetName(index);
field.Type = reader.GetFieldType(index);
field.DataTypeName = reader.GetDataTypeName(index);
fields[index] = field;
if (!ordinals.Contains(field.Name))
ordinals.Add(field.Name, index);
}
// Cache schema info
schema = reader.GetSchemaTable();
// Cache row data
rows = new ArrayList();
while (reader.Read())
{
object[] values = new object[fields.Length];
reader.GetValues(values);
rows.Add(values);
}
// Cache additional results
if (reader.NextResult())
nextResult = new DisconnectedReader(reader);
// Close the reader once all data has been cached
else
reader.Dispose();
// Set the record index before the first record;
this.recordIndex = -1;
this.lastIndex = rows.Count - 1;
}