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 sealed class OleDbDataReader : System.Data.Common.DbDataReader
type OleDbDataReader = class
    inherit DbDataReader
Public NotInheritable Class OleDbDataReader
Inherits DbDataReader
继承
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. 最后,该示例关闭OleDbDataReaderOleDbConnection然后再关闭。Finally, 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 OleDbCommand resuse 对象,还必须关闭对象。例如,在调用Close之后,才能检索输出参数。You 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. 尽管可以在OleDbDataReader存在时访问Close RecordsAffected属性,但在返回值之前始终调用以保证准确的返回值。 RecordsAffectedAlthough 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.

CreateObjRef(Type)

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

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

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.

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.

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.

GetSchemaTable()

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

GetString(Int32)

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

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.

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.

Read()

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

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

IDataRecord.GetData(Int32)

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

IDisposable.Dispose()

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

IEnumerable.GetEnumerator()

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

适用于

另请参阅