OdbcDataReader 类

定义

提供从数据源读取仅向前数据流数据行的方法。 此类不能被继承。

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

示例

以下示例创建一个 OdbcConnection、一个 OdbcCommand和一个 OdbcDataReader。 该示例读取数据,并将其写出到控制台。 最后,该示例关闭 ,然后OdbcConnection关闭 OdbcDataReader

public static void ReadData(string connectionString)
{
    string queryString = "SELECT DISTINCT CustomerID FROM Orders";

    using (OdbcConnection connection = new OdbcConnection(connectionString))
    {
        OdbcCommand command = new OdbcCommand(queryString, connection);

        connection.Open();

        // Execute the DataReader and access the data.
        OdbcDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine("CustomerID={0}", reader[0]);
        }

        // Call Close when done reading.
        reader.Close();
    }
}
Public Sub ReadData(ByVal connectionString As String)
    Dim queryString As String = "SELECT DISTINCT CustomerID FROM Orders"

    Using connection As New OdbcConnection(connectionString)
        Dim command As New OdbcCommand(queryString, connection)

        connection.Open()

        Dim reader As OdbcDataReader = command.ExecuteReader()

        While reader.Read()
            Console.WriteLine("CustomerID={0}", reader(0).ToString)
        End While

        ' Call Close when done reading.
        reader.Close()
    End Using
End Sub

注解

若要创建, OdbcDataReader必须调用 ExecuteReader 对象的方法 OdbcCommand ,而不是直接使用构造函数。

在使用时 OdbcDataReader ,关联的 OdbcConnection 服务正忙于提供服务 OdbcDataReader,除了关闭其他操作之外,其他任何操作都无法执行 OdbcConnection 。 这是在调用方法Close之前OdbcDataReader的情况。 例如,在调用 Close后才能检索输出参数。

正在读取数据时对另一个进程或线程对结果集所做的更改可能对用户 OdbcDataReader可见。 但是,精确行为既取决于驱动程序,又依赖于计时。

IsClosedRecordsAffected 关闭后 OdbcDataReader 可以调用的唯一属性。 有时,必须先呼叫 Close ,然后才能呼叫 RecordsAffected

属性

名称 说明
Depth

获取一个值,该值指示当前行的嵌套深度。

FieldCount

获取当前行中的列数。

HasRows

获取一个值,该值指示是否 OdbcDataReader 包含一行或多行。

IsClosed

指示是否已 OdbcDataReader 关闭。

Item[Int32]

获取给定列序号的指定列的本机格式的值。

Item[String]

获取给定列名称的本机格式指定列的值。

RecordsAffected

获取通过执行 SQL 语句更改、插入或删除的行数。

VisibleFieldCount

获取不隐藏的 DbDataReader 字段数。

(继承自 DbDataReader)

方法

名称 说明
Close()

关闭 OdbcDataReader 对象。

CreateObjRef(Type)

创建一个对象,其中包含生成用于与远程对象通信的代理所需的所有相关信息。

(继承自 MarshalByRefObject)
Dispose()

释放类的 DbDataReader 当前实例使用的所有资源。

(继承自 DbDataReader)
Dispose(Boolean)

释放由托管资源使用 DbDataReader 的非托管资源,并选择性地释放托管资源。

(继承自 DbDataReader)
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
Finalize()

允许对象在垃圾回收回收资源之前尝试释放资源并执行其他清理操作。

GetBoolean(Int32)

获取指定列的值作为布尔值。

GetByte(Int32)

获取指定列作为字节的值。

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

从指定的列偏移量读取缓冲区中的字节流作为数组,从特定的缓冲区偏移量开始。

GetChar(Int32)

获取指定列的值作为字符。

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

从指定的列偏移量读取缓冲区中的字符流作为数组,从特定的缓冲区偏移量开始。

GetData(Int32)

返回指定列序号的一个 IDataReader

GetData(Int32)

返回所请求列的嵌套数据读取器。

(继承自 DbDataReader)
GetDataTypeName(Int32)

获取源数据类型的名称。

GetDate(Int32)

获取作为对象的指定列 DateTime 的值。

GetDateTime(Int32)

获取作为对象的指定列 DateTime 的值。

GetDbDataReader(Int32)

返回 DbDataReader 请求的列序号的对象,该对象可通过提供程序特定的实现重写。

(继承自 DbDataReader)
GetDecimal(Int32)

获取作为对象的指定列 Decimal 的值。

GetDouble(Int32)

获取指定列的值作为双精度浮点数。

GetEnumerator()

返回可用于循环访问数据读取器中的行的一个 IEnumerator 值。

GetFieldType(Int32)

获取 Type 对象数据类型。

GetFieldValue<T>(Int32)

获取指定列的值作为请求的类型。

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

以异步方式获取指定列的值作为请求的类型。

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

以异步方式获取指定列的值作为请求的类型。

(继承自 DbDataReader)
GetFloat(Int32)

获取指定列的值作为单精度浮点数。

GetGuid(Int32)

获取指定列的值作为全局唯一标识符(GUID)。

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetInt16(Int32)

获取指定列作为 16 位有符号整数的值。

GetInt32(Int32)

获取指定列作为 32 位有符号整数的值。

GetInt64(Int32)

获取指定列的值作为 64 位有符号整数。

GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetName(Int32)

获取指定列的名称。

GetOrdinal(String)

获取列序号,给定列的名称。

GetProviderSpecificFieldType(Int32)

获取指定列的提供程序特定类型。

(继承自 DbDataReader)
GetProviderSpecificValue(Int32)

获取作为提供程序特定类型的实例的指定列的值。

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

获取当前行的集合中所有特定于提供程序的属性列。

(继承自 DbDataReader)
GetSchemaTable()

返回一个描述列元数据的 DataTable.OdbcDataReader

GetStream(Int32)

获取从指定列检索数据的流。

(继承自 DbDataReader)
GetString(Int32)

获取指定列的值作为一个 String

GetTextReader(Int32)

获取从列检索数据的文本读取器。

(继承自 DbDataReader)
GetTime(Int32)

获取作为对象的指定列 TimeSpan 的值。

GetType()

获取当前实例的 Type

(继承自 Object)
GetValue(Int32)

获取指定序号处的列的值,其本机格式。

GetValues(Object[])

使用当前行的列值填充对象的数组。

InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。

(继承自 MarshalByRefObject)
IsDBNull(Int32)

获取一个值,该值指示列是包含不存在值还是缺失值。

IsDBNullAsync(Int32, CancellationToken)

异步获取一个值,该值指示列是包含不存在值还是缺失值。

(继承自 DbDataReader)
IsDBNullAsync(Int32)

异步获取一个值,该值指示列是包含不存在值还是缺失值。

(继承自 DbDataReader)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(继承自 MarshalByRefObject)
NextResult()

读取批处理 SQL 语句的结果时,将 OdbcDataReader 转到下一个结果。

NextResultAsync()

读取一批语句的结果时,异步将读取器提升到下一个结果。

(继承自 DbDataReader)
NextResultAsync(CancellationToken)

读取一批语句的结果时,异步将读取器提升到下一个结果。

(继承自 DbDataReader)
Read()

前进 OdbcDataReader 到下一条记录。

ReadAsync()

异步将读取器前进到结果集中的下一条记录。

(继承自 DbDataReader)
ReadAsync(CancellationToken)

异步将读取器前进到结果集中的下一条记录。

(继承自 DbDataReader)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

显式接口实现

名称 说明
IDataRecord.GetData(Int32)

有关此成员的说明,请参阅 GetData(Int32)

(继承自 DbDataReader)
IDisposable.Dispose()

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

释放类的 OdbcDataReader 当前实例使用的所有资源。

IEnumerable.GetEnumerator()

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

返回循环访问集合的枚举器。

扩展方法

名称 说明
AsParallel(IEnumerable)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

CanGetColumnSchema(DbDataReader)

获取一个值,该值指示是否可以 DbDataReader 获取列架构。

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定类型。

GetColumnSchema(DbDataReader)

获取 .DbColumn. 的列架构 (DbDataReader集合)

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。

适用于

另请参阅