DataTableReader Class

Definition

The DataTableReader obtains the contents of one or more DataTable objects in the form of one or more read-only, forward-only result sets.

public sealed class DataTableReader : System.Data.Common.DbDataReader
Inheritance

Inherited Members

System.Data.Common.DbDataReader

System.MarshalByRefObject

System.Object

Remarks

The DataTableReader works much like any other data reader, such as the SqlDataReader, except that the DataTableReader provides for iterating over rows in a DataTable. In other words, it provides for iterating over rows in a cache. The cached data can be modified while the DataTableReader is active, and the reader automatically maintains its position.

When you create a DataTableReader from a DataTable, the resulting DataTableReader object contains one result set with the same data as the DataTable from which it was created, except for any rows that have been marked as deleted. The columns appear in the same order as in the original DataTable. The structure of the returned result is identical in schema and data to the original DataTable. A DataTableReader that was created by calling the CreateDataReader method of a DataSet object contains multiple result sets if the DataSet contains more than one table. The results are in the same sequence as the DataTable objects in the DataTableCollection of the DataSet object.

The returned result set contains only the current version of each DataRow; rows that are marked for deletion are skipped.

The DataTableReader provides a stable iterator; that is, the contents of the DataTableReader are not invalidated if the size of the underlying collection is modified during iteration. For example, if one or more rows in the Rows collection are deleted or removed during iteration, the current position within the DataTableReader is maintained appropriately and it does not invalidate the iterator.

Constructors

DataTableReader(DataTable)

Initializes a new instance of the DataTableReader class by using data from the supplied DataTable.

DataTableReader(DataTable[])

Initializes a new instance of the DataTableReader class using the supplied array of DataTable objects.

Properties

Depth

The depth of nesting for the current row of the DataTableReader.

FieldCount

Returns the number of columns in the current row.

HasRows

Gets a value that indicates whether the DataTableReader contains one or more rows.

IsClosed

Gets a value that indicates whether the DataTableReader is closed.

Item[Int32]

Gets the value of the specified column in its native format given the column ordinal.

Item[String]

Gets the value of the specified column in its native format given the column name.

RecordsAffected

Gets the number of rows inserted, changed, or deleted by execution of the SQL statement.

Methods

Close()

Closes the current DataTableReader.

GetBoolean(Int32)

Gets the value of the specified column as a Boolean.

GetByte(Int32)

Gets the value of the specified column as a byte.

GetBytes(Int32, Int64, Byte[], Int32, Int32)

Reads a stream of bytes starting at the specified column offset into the buffer as an array starting at the specified buffer offset.

GetChar(Int32)

Gets the value of the specified column as a character.

GetChars(Int32, Int64, Char[], Int32, Int32)

Returns the value of the specified column as a character array.

GetDataTypeName(Int32)

Gets a string representing the data type of the specified column.

GetDateTime(Int32)

Gets the value of the specified column as a DateTime object.

GetDecimal(Int32)

Gets the value of the specified column as a Decimal.

GetDouble(Int32)

Gets the value of the column as a double-precision floating point number.

GetEnumerator()

Returns an enumerator that can be used to iterate through the item collection.

GetFieldType(Int32)

Gets the Type that is the data type of the object.

GetFloat(Int32)

Gets the value of the specified column as a single-precision floating point number.

GetGuid(Int32)

Gets the value of the specified column as a globally-unique identifier (GUID).

GetInt16(Int32)

Gets the value of the specified column as a 16-bit signed integer.

GetInt32(Int32)

Gets the value of the specified column as a 32-bit signed integer.

GetInt64(Int32)

Gets the value of the specified column as a 64-bit signed integer.

GetName(Int32)

Gets the value of the specified column as a String.

GetOrdinal(String)

Gets the column ordinal, given the name of the column.

GetProviderSpecificFieldType(Int32)

Gets the type of the specified column in provider-specific format.

GetProviderSpecificValue(Int32)

Gets the value of the specified column in provider-specific format.

GetProviderSpecificValues(Object[])

Fills the supplied array with provider-specific type information for all the columns in the DataTableReader.

GetSchemaTable()

Returns a DataTable that describes the column metadata of the DataTableReader.

GetString(Int32)

Gets the value of the specified column as a string.

GetValue(Int32)

Gets the value of the specified column in its native format.

GetValues(Object[])

Populates an array of objects with the column values of the current row.

IsDBNull(Int32)

Gets a value that indicates whether the column contains non-existent or missing values.

NextResult()

Advances the DataTableReader to the next result set, if any.

Read()

Advances the DataTableReader to the next record.

Extension Methods

CanGetColumnSchema(DbDataReader)
GetColumnSchema(DbDataReader)
Cast<TResult>(IEnumerable)
OfType<TResult>(IEnumerable)
AsParallel(IEnumerable)
AsQueryable(IEnumerable)