DataTableReader 类

定义

DataTableReader 以一个或多个只读、只进结果集的形式获取一个或多个 DataTable 对象的内容。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 ref class DataTableReader sealed : System::Data::Common::DbDataReader
public sealed class DataTableReader : System.Data.Common.DbDataReader
type DataTableReader = class
    inherit DbDataReader
Public NotInheritable Class DataTableReader
Inherits DbDataReader
继承

注解

DataTableReader 工作方式与任何其他数据读取器(如)非常相似, SqlDataReader 不同之处在于, DataTableReader 可用于循环访问中的行 DataTableThe 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. 当处于活动状态时,可以修改缓存的数据 DataTableReader ,并且读取器将自动保持其位置。The cached data can be modified while the DataTableReader is active, and the reader automatically maintains its position.

从创建时 DataTableReader DataTable ,生成的对象将 DataTableReader 包含一个结果集,该结果集的数据与创建它时所用的数据相同 DataTable ,但任何已标记为已删除的行除外。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. 列的显示顺序与原始中的顺序相同 DataTableThe columns appear in the same order as in the original DataTable. 返回的结果的结构在架构和数据上完全相同 DataTableThe structure of the returned result is identical in schema and data to the original DataTable. DataTableReader如果包含多个表,则通过调用对象的方法创建的 CreateDataReader DataSet 包含多个结果集 DataSetA 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. 结果与对象的中的对象的序列相同 DataTable DataTableCollection DataSetThe results are in the same sequence as the DataTable objects in the DataTableCollection of the DataSet object.

返回的结果集仅包含每个的当前版本 DataRow ; 跳过标记为删除的行。The returned result set contains only the current version of each DataRow; rows that are marked for deletion are skipped.

DataTableReader提供一个稳定的迭代器; 也就是说,如果在迭代期间修改了基础集合的大小,则的内容将 DataTableReader 不会失效。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. 例如,如果集合中的一个或多个行在 Rows 迭代期间删除或删除,则中的当前位置 DataTableReader 将相应维护,而不会使迭代器失效。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.

构造函数

DataTableReader(DataTable)

通过使用提供的 DataTableReader 中的数据初始化 DataTable 类的新实例。Initializes a new instance of the DataTableReader class by using data from the supplied DataTable.

DataTableReader(DataTable[])

使用提供的 DataTableReader 对象的数组初始化 DataTable 类的新实例。Initializes a new instance of the DataTableReader class using the supplied array of DataTable objects.

属性

Depth

DataTableReader 的当前行的嵌套深度。The depth of nesting for the current row of the DataTableReader.

FieldCount

返回当前行中的列数。Returns the number of columns in the current row.

HasRows

获取一个值,该值指示 DataTableReader 是否包含一行还是多行。Gets a value that indicates whether the DataTableReader contains one or more rows.

IsClosed

获取一个值,该值指示 DataTableReader 是否已关闭。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

通过执行 SQL 语句获取插入、更改或删除的行数。Gets the number of rows inserted, changed, or deleted by execution of the SQL statement.

VisibleFieldCount

获取 DbDataReader 中未隐藏的字段的数目。Gets the number of fields in the DbDataReader that are not hidden.

(继承自 DbDataReader)

方法

Close()

关闭当前的 DataTableReaderCloses the current DataTableReader.

CloseAsync()

异步关闭 DbDataReader 对象。Asynchronously closes the DbDataReader object.

(继承自 DbDataReader)
CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()

释放 DbDataReader 类的当前实例所使用的所有资源。Releases all resources used by the current instance of the DbDataReader class.

(继承自 DbDataReader)
Dispose(Boolean)

释放由 DbDataReader 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the DbDataReader and optionally releases the managed resources.

(继承自 DbDataReader)
DisposeAsync()

异步释放 DbDataReader 类的当前实例所使用的所有资源。Asynchronously releases all resources used by the current instance of the DbDataReader class.

(继承自 DbDataReader)
Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetBoolean(Int32)

获取指定列的 Boolean 形式的值。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.

GetColumnSchemaAsync(CancellationToken)

这是 GetColumnSchema(DbDataReader) 的异步版本。This is the asynchronous version of GetColumnSchema(DbDataReader). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可以选择接受 cancellationTokenThe cancellationToken can optionally be honored. 默认实现调用同步 GetColumnSchema(DbDataReader) 调用并返回已完成任务。The default implementation invokes the synchronous GetColumnSchema(DbDataReader) call and returns a completed task. 如果传递到已取消 cancellationToken,则默认实现将返回已取消的任务。The default implementation will return a cancelled task if passed an already cancelled cancellationToken. GetColumnSchema(DbDataReader) 引发的异常将通过任务异常属性传递。Exceptions thrown by GetColumnSchema(DbDataReader) will be communicated via the returned Task Exception property.

(继承自 DbDataReader)
GetData(Int32)

返回所请求列的嵌套数据读取器。Returns a nested data reader for the requested column.

(继承自 DbDataReader)
GetDataTypeName(Int32)

获取一个表示指定列的数据类型的字符串。Gets a string representing the data type of the specified column.

GetDateTime(Int32)

DateTime 对象的形式获取指定列的值。Gets the value of the specified column as a DateTime object.

GetDbDataReader(Int32)

返回被请求的列序号的 DbDataReader 对象,可以使用提供程序特定的实现对该对象进行重写。Returns a DbDataReader object for the requested column ordinal that can be overridden with a provider-specific implementation.

(继承自 DbDataReader)
GetDecimal(Int32)

获取指定列的 Decimal 形式的值。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)

获取作为对象的数据类型的 TypeGets the Type that is the data type of the object.

GetFieldValue<T>(Int32)

获取指定列的值作为请求的类型。Gets the value of the specified column as the requested type.

(继承自 DbDataReader)
GetFieldValueAsync<T>(Int32)

异步获取指定列的值作为请求的类型。Asynchronously gets the value of the specified column as the requested type.

(继承自 DbDataReader)
GetFieldValueAsync<T>(Int32, CancellationToken)

异步获取指定列的值作为请求的类型。Asynchronously gets the value of the specified column as the requested type.

(继承自 DbDataReader)
GetFloat(Int32)

以单精度浮点数字的形式获取指定列的值。Gets the value of the specified column as a single-precision floating point number.

GetGuid(Int32)

以全局唯一标识符 (GUID) 的形式获取指定列的值。Gets the value of the specified column as a globally-unique identifier (GUID).

GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetInt16(Int32)

获取指定列的 16 位有符号整数形式的值。Gets the value of the specified column as a 16-bit signed integer.

GetInt32(Int32)

获取指定列的 32 位带符号整数形式的值。Gets the value of the specified column as a 32-bit signed integer.

GetInt64(Int32)

以 64 位有符号整数的形式获取指定列的值。Gets the value of the specified column as a 64-bit signed integer.

GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetName(Int32)

获取指定列的 String 形式的值。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[])

使用 DataTableReader 中所有列的特定于提供程序的类型信息填充提供的数组。Fills the supplied array with provider-specific type information for all the columns in the DataTableReader.

GetSchemaTable()

返回一个 DataTable,它描述 DataTableReader 的列元数据。Returns a DataTable that describes the column metadata of the DataTableReader.

GetSchemaTableAsync(CancellationToken)

这是 GetSchemaTable() 的异步版本。This is the asynchronous version of GetSchemaTable(). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可以选择接受 cancellationTokenThe cancellationToken can optionally be honored. 默认实现调用同步 GetSchemaTable() 调用并返回已完成任务。The default implementation invokes the synchronous GetSchemaTable() call and returns a completed task. 如果传递到已取消 cancellationToken,则默认实现将返回已取消的任务。The default implementation will return a cancelled task if passed an already cancelled cancellationToken. GetSchemaTable() 引发的异常将通过任务异常属性传递。Exceptions thrown by GetSchemaTable() will be communicated via the returned Task Exception property.

(继承自 DbDataReader)
GetStream(Int32)

获取从指定列检索数据的流。Gets a stream to retrieve data from the specified column.

(继承自 DbDataReader)
GetString(Int32)

获取指定列的字符串形式的值。Gets the value of the specified column as a string.

GetTextReader(Int32)

获取文本读取器以从列中检索数据。Gets a text reader to retrieve data from the column.

(继承自 DbDataReader)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
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.

InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
IsDBNull(Int32)

获取一个值,该值指示列中是否包含不存在的或缺少的值。Gets a value that indicates whether the column contains non-existent or missing values.

IsDBNullAsync(Int32)

异步获取一个值,该值指示列中是否包含不存在的或缺少的值。Asynchronously gets a value that indicates whether the column contains non-existent or missing values.

(继承自 DbDataReader)
IsDBNullAsync(Int32, CancellationToken)

异步获取一个值,该值指示列中是否包含不存在的或缺少的值。Asynchronously gets a value that indicates whether the column contains non-existent or missing values.

(继承自 DbDataReader)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
NextResult()

使 DataTableReader 前进到下一个结果集(如果有)。Advances the DataTableReader to the next result set, if any.

NextResultAsync()

在读取一批语句的结果时,使读取器异步前进到下一个结果。Asynchronously advances the reader to the next result when reading the results of a batch of statements.

(继承自 DbDataReader)
NextResultAsync(CancellationToken)

在读取一批语句的结果时,使读取器异步前进到下一个结果。Asynchronously advances the reader to the next result when reading the results of a batch of statements.

(继承自 DbDataReader)
Read()

DataTableReader 前进到下一条记录。Advances the DataTableReader to the next record.

ReadAsync()

使读取器异步前进到结果集中的下一条记录。Asynchronously advances the reader to the next record in a result set.

(继承自 DbDataReader)
ReadAsync(CancellationToken)

使读取器异步前进到结果集中的下一条记录。Asynchronously advances the reader to the next record in a result set.

(继承自 DbDataReader)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

IDataReader.Close()

有关此成员的说明,请参见 Close()For a description of this member, see Close().

(继承自 DbDataReader)
IDataReader.GetSchemaTable()

有关此成员的说明,请参见 GetSchemaTable()For a description of this member, see GetSchemaTable().

(继承自 DbDataReader)
IDataRecord.GetData(Int32)

有关此成员的说明,请参见 GetData(Int32)For a description of this member, see GetData(Int32).

(继承自 DbDataReader)

扩展方法

CanGetColumnSchema(DbDataReader)

获取一个值,指示 DbDataReader 是否可以获取列架构。Gets a value that indicates whether a DbDataReader can get a column schema.

GetColumnSchema(DbDataReader)

获取 DbDataReader 的列架构(DbColumn 集合)。Gets the column schema (DbColumn collection) for a DbDataReader.

GetBoolean(DbDataReader, String)

获取指定列的布尔值形式的值。Gets the value of the specified column as a Boolean.

GetByte(DbDataReader, String)

以字节的形式获取指定列的值。Gets the value of the specified column as a byte.

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

从指定列中指定索引处开始读取指定字节数,并将其写入缓冲区中从指定位置开始的缓冲区。Reads a specified number of bytes from the specified column starting at a specified index and writes them to a buffer starting at a specified position in the buffer.

GetChar(DbDataReader, String)

作为单个字符获取指定列的值。Gets the value of the specified column as a single character.

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

从指定列中指定索引处开始读取指定字符数,并将其写入从指定位置开始的缓冲区。Reads a specified number of characters from a specified column starting at a specified index, and writes them to a buffer starting at a specified position.

GetData(DbDataReader, String)

返回所请求列的嵌套数据读取器。Returns a nested data reader for the requested column.

GetDataTypeName(DbDataReader, String)

获取指定列的数据类型的名称。Gets name of the data type of the specified column.

GetDateTime(DbDataReader, String)

DateTime 对象的形式获取指定列的值。Gets the value of the specified column as a DateTime object.

GetDecimal(DbDataReader, String)

获取指定列的 Decimal 形式的值。Gets the value of the specified column as a Decimal.

GetDouble(DbDataReader, String)

获取作为双精度浮点数的指定列的值。Gets the value of the specified column as a double-precision floating point number.

GetFieldType(DbDataReader, String)

获取指定列的数据类型。Gets the data type of the specified column.

GetFieldValue<T>(DbDataReader, String)

获取指定列的值作为请求的类型。Gets the value of the specified column as the requested type.

GetFieldValueAsync<T>(DbDataReader, String, CancellationToken)

异步获取指定列的值作为请求的类型。Asynchronously gets the value of the specified column as the requested type.

GetFloat(DbDataReader, String)

以单精度浮点数字的形式获取指定列的值。Gets the value of the specified column as a single-precision floating point number.

GetGuid(DbDataReader, String)

作为全局唯一标识符 (GUID) 获取指定列的值。Gets the value of the specified column as a globally unique identifier (GUID).

GetInt16(DbDataReader, String)

获取指定列的 16 位有符号整数形式的值。Gets the value of the specified column as a 16-bit signed integer.

GetInt32(DbDataReader, String)

获取指定列的 32 位带符号整数形式的值。Gets the value of the specified column as a 32-bit signed integer.

GetInt64(DbDataReader, String)

以 64 位有符号整数的形式获取指定列的值。Gets the value of the specified column as a 64-bit signed integer.

GetProviderSpecificFieldType(DbDataReader, String)

获取指定列的特定于提供程序的类型。Gets the provider-specific type of the specified column.

GetProviderSpecificValue(DbDataReader, String)

以特定于提供程序的类型实例的形式获取指定列的值。Gets the value of the specified column as an instance of a provider-specific type.

GetStream(DbDataReader, String)

获取从指定列检索数据的流。Gets a stream to retrieve data from the specified column.

GetString(DbDataReader, String)

String 实例的形式获取指定列的值。Gets the value of the specified column as an instance of String.

GetTextReader(DbDataReader, String)

获取文本读取器以从列中检索数据。Gets a text reader to retrieve data from the column.

GetValue(DbDataReader, String)

Object 实例的形式获取指定列的值。Gets the value of the specified column as an instance of Object.

IsDBNull(DbDataReader, String)

获取一个值,该值指示列中是否包含不存在或丢失的值。Gets a value that indicates whether the column contains nonexistent or missing values.

IsDBNullAsync(DbDataReader, String, CancellationToken)

异步获取一个值,该值指示列中是否包含不存在的或缺少的值。Asynchronously gets a value that indicates whether the column contains non-existent or missing values.

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

ConfigureAwait(IAsyncDisposable, Boolean)

配置如何执行从异步可处置项返回的任务的等待。Configures how awaits on the tasks returned from an async disposable are performed.

适用于