OleDbDataReader 類別

定義

提供自資料來源讀取順向資料流的資料列的方法。 此類別無法獲得繼承。

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、、 OleDbCommandOleDbDataReader。 此範例會讀取數據,並將它寫出主控台。 最後,此範例會 OleDbDataReader 關閉 ,然後 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 ,而不是直接使用建構函式。

在您關閉 OleDbConnection之前,請先關閉 OleDbDataReader 物件。 如果您打算重新使用 OleDbCommand 物件,OleDbDataReader您也必須關閉物件。例如,在呼叫 Close之後,您才能擷取輸出參數。

正在讀取資料時,OleDbDataReader 使用者會看到另一個處理序或執行緒對結果集所進行的變更。 但精確的行為取決於時間點。

IsClosedRecordsAffected 是在關閉 OleDbDataReader 後唯一可呼叫的屬性。 RecordsAffected雖然在 存在時OleDbDataReader可以存取 屬性,但請一律呼叫 ,再傳Close回的值RecordsAffected,以確保正確的傳回值。

屬性

Depth

取得值,表示目前資料列的巢狀深度。

FieldCount

取得目前資料列中的資料行數目。

HasRows

取得值,指出 OleDbDataReader 是否包含一個或多個資料列。

IsClosed

指出資料讀取器是否關閉。

Item[Int32]

提供資料行序數,取得使用原生格式的指定資料行值。

Item[String]

提供資料行名稱,取得使用原生格式的指定資料行值。

RecordsAffected

取得因執行 SQL 陳述式所變更、插入或刪除的資料列數目。

VisibleFieldCount

取得 OleDbDataReader 中沒有隱藏的欄位數。

方法

Close()

關閉 OleDbDataReader 物件。

CloseAsync()

非同步關閉 DbDataReader 物件。

(繼承來源 DbDataReader)
CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Dispose()

釋放 DbDataReader 類別目前的執行個體所使用的全部資源。

(繼承來源 DbDataReader)
Dispose(Boolean)

釋放 DbDataReader 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

(繼承來源 DbDataReader)
DisposeAsync()

以非同步方式將 DbDataReader 類別的目前執行個體所使用所有資源釋出。

(繼承來源 DbDataReader)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
Finalize()

允許物件在記憶體回收進行回收之前,嘗試釋放資源並執行其他清除作業。

GetBoolean(Int32)

取得指定之資料行的值做為布林值 (Boolean)。

GetByte(Int32)

取得指定資料行的值做為位元組。

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

從指定的資料行位移將位元組資料流讀入做為陣列的緩衝區,開始於指定的緩衝區位移。

GetChar(Int32)

取得指定資料行的值做為字元。

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

從指定的資料行位移將字元資料流讀取到緩衝區中,作為以指定緩衝區位移開頭的陣列。

GetColumnSchemaAsync(CancellationToken)

這是 GetColumnSchema(DbDataReader) 的非同步版本。 提供者應該覆寫為適當的實作。 您可以選擇性地接受 cancellationToken。 預設實作會叫用同步GetColumnSchema(DbDataReader)呼叫並傳回完成的工作。 如果傳遞一個已經被取消的 cancellationToken,預設實作會傳回已取消的工作。 GetColumnSchema(DbDataReader) 擲回的例外狀況會透過傳回的工作例外狀況屬性來傳送。

(繼承來源 DbDataReader)
GetData(Int32)

傳回要求之資料行序數的 OleDbDataReader 物件。

GetDataTypeName(Int32)

取得來源資料型別的名稱。

GetDateTime(Int32)

取得指定之資料行的值做為 DateTime 物件。

GetDbDataReader(Int32)

傳回所要求資料行序數的 DbDataReader 物件,可使用提供者特定的實作 (Implementation) 覆寫。

(繼承來源 DbDataReader)
GetDecimal(Int32)

取得指定之資料行的值做為 Decimal 物件。

GetDouble(Int32)

取得指定之資料行的值做為雙精度浮點數。

GetEnumerator()

傳回 IEnumerator,可用來逐一查看資料讀取器中的資料列。

GetFieldType(Int32)

取得 Type,即是物件的資料型別。

GetFieldValue<T>(Int32)

取得所指定資料行值作為要求類型。

(繼承來源 DbDataReader)
GetFieldValueAsync<T>(Int32)

以非同步方式取得所指定資料行的值作為要求類型。

(繼承來源 DbDataReader)
GetFieldValueAsync<T>(Int32, CancellationToken)

以非同步方式取得所指定資料行的值作為要求類型。

(繼承來源 DbDataReader)
GetFloat(Int32)

取得指定資料行的值做為單精確度浮點數。

GetGuid(Int32)

從指定的資料行取得通用唯一識別碼 (GUID) 形式的值。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetInt16(Int32)

取得指定資料行的值做為 16 位元帶正負號的整數。

GetInt32(Int32)

取得指定資料行的值作為 32 位元帶正負號的整數。

GetInt64(Int32)

取得指定資料行的值做為 64 位元帶正負號的整數 (Signed Integer)。

GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetName(Int32)

取得指定資料行的名稱。

GetOrdinal(String)

提供資料行的名稱,取得資料行序數。

GetProviderSpecificFieldType(Int32)

取得指定資料行的提供者特定類型。

(繼承來源 DbDataReader)
GetProviderSpecificValue(Int32)

取得所指定資料行值作為提供者特定類型的執行個體。

(繼承來源 DbDataReader)
GetProviderSpecificValues(Object[])

為目前的資料列在集合中取得所有提供者特定的屬性資料行。

(繼承來源 DbDataReader)
GetSchemaTable()

傳回 DataTable,以描述 OleDbDataReader 的資料行中繼資料。

GetSchemaTableAsync(CancellationToken)

這是 GetSchemaTable() 的非同步版本。 提供者應該覆寫為適當的實作。 您可以選擇性地接受 cancellationToken。 預設實作會叫用同步GetSchemaTable()呼叫並傳回完成的工作。 如果傳遞一個已經被取消的 cancellationToken,預設實作會傳回已取消的工作。 GetSchemaTable() 擲回的例外狀況會透過傳回的工作例外狀況屬性來傳送。

(繼承來源 DbDataReader)
GetStream(Int32)

取得資料流以從指定的資料行擷取資料。

(繼承來源 DbDataReader)
GetString(Int32)

取得指定的資料行值做為字串。

GetTextReader(Int32)

取得文字讀取器以從資料行擷取資料。

(繼承來源 DbDataReader)
GetTimeSpan(Int32)

取得指定之資料行的值做為 TimeSpan 物件。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetValue(Int32)

取得使用原生格式的指定序數的資料行值。

GetValues(Object[])

使用目前資料列的資料行值填入物件陣列。

InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
IsDBNull(Int32)

取得值,這個值表示資料行是否包含不存在或遺漏的值。

IsDBNullAsync(Int32)

以非同步方式取得值,指出資料行是否包含不存在或遺漏的值。

(繼承來源 DbDataReader)
IsDBNullAsync(Int32, CancellationToken)

以非同步方式取得值,指出資料行是否包含不存在或遺漏的值。

(繼承來源 DbDataReader)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
NextResult()

在讀取批次 SQL 陳述式的結果時,會將資料讀取器向前移到下一個結果。

NextResultAsync()

在讀取陳述式批次的結果時,以非同步方式將讀取器向前移到下一個結果。

(繼承來源 DbDataReader)
NextResultAsync(CancellationToken)

在讀取陳述式批次的結果時,以非同步方式將讀取器向前移到下一個結果。

(繼承來源 DbDataReader)
Read()

OleDbDataReader 推進到下一筆記錄。

ReadAsync()

以非同步方式將讀取器向前移到結果集中的下一筆記錄。

(繼承來源 DbDataReader)
ReadAsync(CancellationToken)

以非同步方式將讀取器向前移到結果集中的下一筆記錄。

(繼承來源 DbDataReader)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

IDataRecord.GetData(Int32)

傳回指定之資料行序數的 IDataReader

IDataRecord.GetData(Int32)

如需這個成員的說明,請參閱 GetData(Int32)

(繼承來源 DbDataReader)
IDisposable.Dispose()

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

OleDbDataReader 類別的目前執行個體所使用的資源釋出。

IEnumerable.GetEnumerator()

傳回逐一查看集合的列舉值。

擴充方法

CanGetColumnSchema(DbDataReader)

取得值,指出 DbDataReader 是否可取得資料行結構描述。

GetColumnSchema(DbDataReader)

取得 DbDataReader 的資料行結構描述 (DbColumn 集合)。

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於

另請參閱