SqlDataReader.GetFieldValueAsync<T>(Int32, CancellationToken) 方法

定義

非同步取得指定之資料行的值做為型別。Asynchronously gets the value of the specified column as a type. GetFieldValue<T>(Int32) 是這個方法的同步版本。GetFieldValue<T>(Int32) is the synchronous version of this method.

public:
generic <typename T>
 override System::Threading::Tasks::Task<T> ^ GetFieldValueAsync(int i, System::Threading::CancellationToken cancellationToken);
public override System.Threading.Tasks.Task<T> GetFieldValueAsync<T> (int i, System.Threading.CancellationToken cancellationToken);
override this.GetFieldValueAsync : int * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'T>

類型參數

T

要傳回的值型别。The type of the value to be returned.

參數

i
Int32

要擷取的資料行。The column to be retrieved.

cancellationToken
CancellationToken

取消指令,其會傳播說明應該取消作業的通知。The cancellation instruction, which propagates a notification that operations should be canceled. 這並不保證取消。This does not guarantee the cancellation. 如果設定為 CancellationToken.None,就會使這個方法相當於 IsDBNull(Int32)A setting of CancellationToken.None makes this method equivalent to IsDBNull(Int32). 傳回的工作必須標記為已取消。The returned task must be marked as cancelled.

傳回

Task<T>

傳回的型別物件。The returned type object.

例外狀況

在資料擷取期間,連線中斷或關閉。The connection drops or is closed during the data retrieval.

SqlDataReader在資料擷取期間已關閉。The SqlDataReader is closed during the data retrieval.

沒有可供讀取的資料 (例如,第一個 Read() 沒有被呼叫,或傳回 false)。There is no data ready to be read (for example, the first Read() hasn't been called, or returned false).

嘗試在循序模式下讀取先前讀取的資料行。Tried to read a previously-read column in sequential mode.

有進行中的非同步作業。There was an asynchronous operation in progress. 當在循序模式中執行時,此適用於所有 Get* 方法,因為在讀取資料流時可能會呼叫它們。This applies to all Get* methods when running in sequential mode, as they could be called while reading a stream.

在連接字串中指定了 Context Connection=trueContext Connection=true is specified in the connection string.

嘗試讀取不存在的資料行。Trying to read a column that does not exist.

資料行的值是 null (IsDBNull(Int32) == true),擷取非 SQL 型別。The value of the column was null (IsDBNull(Int32) == true), retrieving a non-SQL type.

T 不符合 SQL Server 傳回的類型,或無法轉換。T doesn't match the type returned by SQL Server or cannot be cast.

備註

T 可以是下列其中一種類型:T can be one of the following types:

BooleanBoolean ByteByte CharChar DateTimeDateTime
DateTimeOffsetDateTimeOffset DecimalDecimal DoubleDouble 浮動Float
GuidGuid Int16Int16 Int32Int32 Int64Int64
SqlBooleanSqlBoolean SqlByteSqlByte SqlDateTimeSqlDateTime SqlDecimalSqlDecimal
SqlDoubleSqlDouble SqlGuidSqlGuid SqlInt16SqlInt16 SqlInt32SqlInt32
SqlInt64SqlInt64 SqlMoneySqlMoney SqlSingleSqlSingle SqlStringSqlString
StringString UDT,可以是任何以 SqlUserDefinedTypeAttribute標記的 CLR 型別。UDT, which can be any CLR type marked with SqlUserDefinedTypeAttribute.

如需詳細資訊,請參閱SqlClient 串流支援For more information, see SqlClient Streaming Support.

適用於