OdbcDataReader 類別

定義

提供自資料來源讀取順向資料流的資料列的方法。Provides a way of reading a forward-only stream of data rows from a data source. 此類別無法獲得繼承。This class cannot be inherited.

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

範例

下列範例會建立 OdbcConnectionOdbcCommandOdbcDataReaderThe following example creates an OdbcConnection, an OdbcCommand, and an OdbcDataReader. 此範例會讀取資料,並將資料寫出至主控台。The example reads through the data, writing it out to the console. 最後,此範例會關閉 OdbcDataReader ,然後再關閉 OdbcConnectionFinally, the example closes the OdbcDataReader, and then the OdbcConnection.

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 ,而不是直接使用函數。To create an OdbcDataReader, you must call the ExecuteReader method of the OdbcCommand object, instead of directly using a constructor.

使用時 OdbcDataReader ,相關聯的 OdbcConnection 會忙於處理 OdbcDataReader ,而不會在關閉它的情況下對其他作業執行其他作業 OdbcConnectionWhile the OdbcDataReader is being used, the associated OdbcConnection is busy serving the OdbcDataReader, and no other operations can be performed on the OdbcConnection other than closing it. 在呼叫的方法之前,會發生這種情況 Close OdbcDataReaderThis is the case until the Close method of the OdbcDataReader is called. 例如,在呼叫之後,您就無法取得輸出參數 CloseFor example, you cannot retrieve output parameters until after you call Close.

正在讀取資料時,OdbcDataReader 使用者會看到另一個處理序或執行緒對結果集所進行的變更。Changes made to a result set by another process or thread while data is being read may be visible to the user of the OdbcDataReader. 不過,精確的行為是與驅動程式和時間相依。However, the precise behavior is both driver and timing dependent.

IsClosedRecordsAffected 是在關閉 OdbcDataReader 後唯一可呼叫的屬性。IsClosed and RecordsAffected are the only properties that you can call after the OdbcDataReader is closed. 有時候,您必須先呼叫, Close 然後才能呼叫 RecordsAffectedSometimes, you must call Close before you can call RecordsAffected.

屬性

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

取得值,指出 OdbcDataReader 是否包含一個或多個資料列。Gets a value that indicates whether the OdbcDataReader contains one or more rows.

IsClosed

指出 OdbcDataReader 是否關閉。Indicates whether the OdbcDataReader 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

取得 DbDataReader 中沒有隱藏的欄位數。Gets the number of fields in the DbDataReader that are not hidden.

(繼承來源 DbDataReader)

方法

Close()

關閉 OdbcDataReader 物件。Closes the OdbcDataReader object.

CloseAsync()

非同步關閉 DbDataReader 物件。Asynchronously closes the DbDataReader object.

(繼承來源 DbDataReader)
CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。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 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。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)

取得指定之資料行的值做為布林值 (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 from the specified column offset into the buffer as an array, starting at the particular 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 particular 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)

傳回指定之資料行序數的 IDataReaderReturns an IDataReader for the specified column ordinal.

GetData(Int32)

傳回所要求資料行的巢狀資料讀取器。Returns a nested data reader for the requested column.

(繼承來源 DbDataReader)
GetDataTypeName(Int32)

取得來源資料型別的名稱。Gets the name of the source data type.

GetDate(Int32)

取得指定之資料行的值做為 DateTime 物件。Gets the value of the specified column as a DateTime object.

GetDateTime(Int32)

取得指定之資料行的值做為 DateTime 物件。Gets the value of the specified column as a DateTime object.

GetDbDataReader(Int32)

傳回所要求資料行序數的 DbDataReader 物件,可使用提供者特定的實作 (Implementation) 覆寫。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()

傳回 IEnumerator,可用來逐一查看資料讀取器中的資料列。Returns an IEnumerator that can be used to iterate through the rows in the data reader.

GetFieldType(Int32)

取得 Type,即是物件的資料型別。Gets 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 位元帶正負號的整數 (Signed Integer)。Gets the value of the specified column as a 64-bit signed integer.

GetLifetimeService()
已過時。

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。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,以描述 OdbcDataReader 的資料行中繼資料。Returns a DataTable that describes the column metadata of the OdbcDataReader.

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)

取得指定的資料行值做為 StringGets the value of the specified column as a String.

GetTextReader(Int32)

取得文字讀取器以從資料行擷取資料。Gets a text reader to retrieve data from the column.

(繼承來源 DbDataReader)
GetTime(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 陳述式的結果時,將 OdbcDataReader 前進到下一個結果。Advances the OdbcDataReader 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()

OdbcDataReader 推進到下一筆記錄。Advances the OdbcDataReader 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)
IDisposable.Dispose()

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

釋放 OdbcDataReader 類別目前的執行個體所使用的全部資源。Releases all resources used by the current instance of the OdbcDataReader class.

IEnumerable.GetEnumerator()

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

傳回逐一查看集合的列舉值。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.

適用於

另請參閱