DbCommand.ExecuteScalarAsync DbCommand.ExecuteScalarAsync DbCommand.ExecuteScalarAsync DbCommand.ExecuteScalarAsync Method

Definition

Implements the asynchronous version of ExecuteScalar(), but returns a Task synchronously, blocking the calling thread.

Overloads

ExecuteScalarAsync(CancellationToken) ExecuteScalarAsync(CancellationToken) ExecuteScalarAsync(CancellationToken)

This is the asynchronous version of ExecuteScalar(). Providers should override with an appropriate implementation. The cancellation token may optionally be ignored.

The default implementation invokes the synchronous ExecuteScalar() method and returns a completed task, blocking the calling thread. The default implementation will return a cancelled task if passed an already cancelled cancellation token. Exceptions thrown by ExecuteScalar will be communicated via the returned Task Exception property.

Do not invoke other methods and properties of the DbCommand object until the returned Task is complete.

ExecuteScalarAsync() ExecuteScalarAsync() ExecuteScalarAsync() ExecuteScalarAsync()

An asynchronous version of ExecuteScalar(), which executes the query and returns the first column of the first row in the result set returned by the query. All other columns and rows are ignored.

Invokes ExecuteScalarAsync(CancellationToken) with CancellationToken.None.

Remarks

For more information about asynchronous programming, see Asynchronous Programming.

ExecuteScalarAsync(CancellationToken) ExecuteScalarAsync(CancellationToken) ExecuteScalarAsync(CancellationToken)

This is the asynchronous version of ExecuteScalar(). Providers should override with an appropriate implementation. The cancellation token may optionally be ignored.

The default implementation invokes the synchronous ExecuteScalar() method and returns a completed task, blocking the calling thread. The default implementation will return a cancelled task if passed an already cancelled cancellation token. Exceptions thrown by ExecuteScalar will be communicated via the returned Task Exception property.

Do not invoke other methods and properties of the DbCommand object until the returned Task is complete.

public:
 virtual System::Threading::Tasks::Task<System::Object ^> ^ ExecuteScalarAsync(System::Threading::CancellationToken cancellationToken);
public virtual System.Threading.Tasks.Task<object> ExecuteScalarAsync (System.Threading.CancellationToken cancellationToken);
abstract member ExecuteScalarAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<obj>
override this.ExecuteScalarAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<obj>
Parameters
cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

A task representing the asynchronous operation.

Exceptions

An error occurred while executing the command text.

Remarks

For more information about asynchronous programming, see Asynchronous Programming.

See Also

ExecuteScalarAsync() ExecuteScalarAsync() ExecuteScalarAsync() ExecuteScalarAsync()

An asynchronous version of ExecuteScalar(), which executes the query and returns the first column of the first row in the result set returned by the query. All other columns and rows are ignored.

Invokes ExecuteScalarAsync(CancellationToken) with CancellationToken.None.

public:
 System::Threading::Tasks::Task<System::Object ^> ^ ExecuteScalarAsync();
public System.Threading.Tasks.Task<object> ExecuteScalarAsync ();
member this.ExecuteScalarAsync : unit -> System.Threading.Tasks.Task<obj>
Public Function ExecuteScalarAsync () As Task(Of Object)
Returns

A task representing the asynchronous operation.

Exceptions

An error occurred while executing the command text.

Remarks

For more information about asynchronous programming, see Asynchronous Programming.

See Also

Applies to