DbDataReader.GetFieldValueAsync Method

Definition

Asynchronously gets the value of the specified column as the requested type.

Overloads

GetFieldValueAsync<T>(Int32)

Asynchronously gets the value of the specified column as the requested type.

GetFieldValueAsync<T>(Int32, CancellationToken)

Asynchronously gets the value of the specified column as the requested type.

GetFieldValueAsync<T>(Int32)

Source:
DbDataReader.cs
Source:
DbDataReader.cs
Source:
DbDataReader.cs

Asynchronously gets the value of the specified column as the requested type.

public System.Threading.Tasks.Task<T> GetFieldValueAsync<T> (int ordinal);

Type Parameters

T

The type of the value to be returned.

Parameters

ordinal
Int32

The zero-based column ordinal.

Returns

Task<T>

A task whose Result contains the value of the specified column.

Exceptions

The connection was dropped or closed during data retrieval.

-or-

The data reader was closed during the data retrieval.

-or-

There is no data ready to be read (for example, the first Read() hasn't been called, or it returned false).

-or-

Tried to read a previously-read column in sequential mode.

-or-

There was an asynchronous operation in progress. This applies to all Get_*_ methods when running in sequential mode, as they could be called while reading a stream.

The column index is out of range.

The value returned by the database doesn't match or cannot be cast to T.

Remarks

This asynchronous method is only needed to avoid blocking the calling thread when the reader is created in sequential mode.

If sequential mode isn't specified, all column values should become available in memory each time ReadAsync completes, and calling the synchronous version of the method shouldn't block the calling thread.

The default implementation of this asynchronous method invokes its synchronous counterpart and returns a completed Task, potentially blocking the calling thread.

Data providers that support asynchronous programming should override the default implementation using asynchronous I/O operations.

Other methods and properties of the DbDataReader object should not be invoked while the returned Task is not yet completed.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

GetFieldValueAsync<T>(Int32, CancellationToken)

Source:
DbDataReader.cs
Source:
DbDataReader.cs
Source:
DbDataReader.cs

Asynchronously gets the value of the specified column as the requested type.

public virtual System.Threading.Tasks.Task<T> GetFieldValueAsync<T> (int ordinal, System.Threading.CancellationToken cancellationToken);

Type Parameters

T

The type of the value to be returned.

Parameters

ordinal
Int32

The zero-based column ordinal.

cancellationToken
CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<T>

A task whose Result contains the value of the specified column.

Exceptions

The connection was dropped or closed during data retrieval.

-or-

The data reader was closed during the data retrieval.

-or-

There is no data ready to be read (for example, the first Read() hasn't been called, or it returned false).

-or-

Tried to read a previously-read column in sequential mode.

-or-

There was an asynchronous operation in progress. This applies to all Get_*_ methods when running in sequential mode, as they could be called while reading a stream.

The column index is out of range.

The value returned by the database doesn't match or cannot be cast to T.

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This asynchronous method is only needed to avoid blocking the calling thread when the reader is created in sequential mode.

If sequential mode isn't specified, all column values should become available in memory each time ReadAsync completes, and calling the synchronous version of the method shouldn't block the calling thread.

The default implementation of this asynchronous method invokes its synchronous counterpart and returns a completed Task, potentially blocking the calling thread. The default implementation also returns a cancelled task if passed an already cancelled cancellation token.

Data providers that support asynchronous programming should override the default implementation using asynchronous I/O operations.

This method accepts a cancellation token that can be used to request the operation to be cancelled early. Implementations may ignore this request.

Other methods and properties of the DbDataReader object should not be invoked while the returned Task is not yet completed.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0