OleDbDataReader 类

定义

提供从数据源读取数据行的只进流的方法。Provides a way of reading a forward-only stream of data rows from a data source. 此类不能被继承。This class cannot be inherited.

public ref class OleDbDataReader sealed : System::Data::Common::DbDataReader
public ref class OleDbDataReader sealed : MarshalByRefObject, IDisposable, System::Collections::IEnumerable, System::Data::IDataReader
public sealed class OleDbDataReader : System.Data.Common.DbDataReader
public sealed class OleDbDataReader : MarshalByRefObject, IDisposable, System.Collections.IEnumerable, System.Data.IDataReader
type OleDbDataReader = class
    inherit DbDataReader
type OleDbDataReader = class
    inherit MarshalByRefObject
    interface IDataReader
    interface IDisposable
    interface IDataRecord
    interface IEnumerable
Public NotInheritable Class OleDbDataReader
Inherits DbDataReader
Public NotInheritable Class OleDbDataReader
Inherits MarshalByRefObject
Implements IDataReader, IDisposable, IEnumerable
继承
OleDbDataReader
继承
继承
OleDbDataReader
实现

示例

下面的示例创建一个 OleDbConnection 、一个 OleDbCommand 和一个 OleDbDataReaderThe following example creates an OleDbConnection, an OleDbCommand, and an OleDbDataReader. 该示例将读取数据,并将其写出到控制台。The example reads through the data, writing it out to the console. 最后,该示例关闭 OleDbDataReader ,然后再关闭 OleDbConnectionFinally, the example closes the OleDbDataReader and then the OleDbConnection.

public static void ReadData(string connectionString, string queryString)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        OleDbCommand command = new OleDbCommand(queryString, connection);

        connection.Open();
        OleDbDataReader reader = command.ExecuteReader();

        while (reader.Read())
        {
            Console.WriteLine(reader[0].ToString());
        }
        reader.Close();
    }
}
Public Sub ReadData(ByVal connectionString As String, _
    ByVal queryString As String)
    Using connection As New OleDbConnection(connectionString)
        Dim command As New OleDbCommand(queryString, connection)

        connection.Open()

        Dim reader As OleDbDataReader = command.ExecuteReader()
        While reader.Read()
            Console.WriteLine(reader(0).ToString())
        End While
        reader.Close()
    End Using
End Sub

注解

若要创建 OleDbDataReader ,必须调用对象的 ExecuteReader 方法 OleDbCommand ,而不是直接使用构造函数。To create an OleDbDataReader, you must call the ExecuteReader method of the OleDbCommand object, instead of directly using a constructor.

在关闭之前 OleDbConnection ,请先关闭 OleDbDataReader 对象。Before you close the OleDbConnection, first close the OleDbDataReader object. OleDbDataReader如果计划 resuse 对象,还必须关闭对象 OleDbCommand 。例如,在调用之后,才能检索输出参数 CloseYou must also close the OleDbDataReader object if you plan to resuse an OleDbCommand object.For example, you cannot retrieve output parameters until after you call Close.

读取数据时,另一进程或线程对结果集所做的更改可能对 OleDbDataReader 的用户可见。Changes made to a result set by another process or thread while data is being read may be visible to the user of the OleDbDataReader. 但是,确切的行为与时间有关。However, the precise behavior is timing dependent.

IsClosedRecordsAffected 是在关闭 OleDbDataReader 后可以调用的唯一属性。IsClosed and RecordsAffected are the only properties that you can call after the OleDbDataReader is closed. 尽管 RecordsAffected 可以在存在时访问属性,但在 OleDbDataReader Close 返回值之前始终调用 RecordsAffected 以保证准确的返回值。Although the RecordsAffected property may be accessed while the OleDbDataReader exists, always call Close before returning the value of RecordsAffected to guarantee an accurate return value.

属性

Depth

获取一个值,用于指示当前行的嵌套深度。Gets a value that indicates the depth of nesting for the current row.

FieldCount

获取当前行中的列数。Gets the number of columns in the current row.

HasRows

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

IsClosed

指示是否可关闭数据读取器。Indicates whether the data reader 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 changed, inserted, or deleted by execution of the SQL statement.

VisibleFieldCount

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

方法

Close()

关闭 OleDbDataReader 对象。Closes the OleDbDataReader object.

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)
Finalize()

允许对象在被“垃圾回收”之前尝试释放资源并执行其他清理操作。Allows the object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

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 from the specified column offset into the buffer as an array starting at the given buffer offset.

GetChar(Int32)

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

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

从给定的缓冲区偏移量开始,按指定的列偏移量将字符流作为数组读入缓冲区。Reads a stream of characters from the specified column offset into the buffer as an array starting at the given buffer offset.

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)

返回请求的列序号的 OleDbDataReader 对象。Returns an OleDbDataReader object for the requested column ordinal.

GetDataTypeName(Int32)

获取源数据类型的名称。Gets the name of the source data type.

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 object.

GetDouble(Int32)

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

GetEnumerator()

返回一个可用于循环访问数据读取器中的行的 IEnumeratorReturns an IEnumerator that can be used to iterate through the rows in the data reader.

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)

获取指定列的名称。Gets the name of the specified column.

GetOrdinal(String)

在给定列名时获取相应的列序号。Gets the column ordinal, given the name of the column.

GetProviderSpecificFieldType(Int32)

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

(继承自 DbDataReader)
GetProviderSpecificValue(Int32)

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

(继承自 DbDataReader)
GetProviderSpecificValues(Object[])

在当前行的集合中获取提供程序特定的所有属性列。Gets all provider-specific attribute columns in the collection for the current row.

(继承自 DbDataReader)
GetSchemaTable()

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

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)
GetTimeSpan(Int32)

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

GetType()

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

(继承自 Object)
GetValue(Int32)

获取以本机格式表示的指定序号处的列的值。Gets the value of the column at the specified ordinal 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 nonexistent 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()

在读取一批 SQL 语句的结果时,使数据读取器前进到下一个结果。Advances the data reader to the next result, when reading the results of batch SQL statements.

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()

OleDbDataReader 前进到下一条记录。Advances the OleDbDataReader 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)

返回指定列序号的 IDataReaderReturns an IDataReader for the specified column ordinal.

IDataRecord.GetData(Int32)

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

(继承自 DbDataReader)
IDisposable.Dispose()

此 API 支持产品基础结构,不能在代码中直接使用。

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

IEnumerable.GetEnumerator()

返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection.

扩展方法

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.

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.

适用于

另请参阅