DbCommand.ExecuteScalarAsync Method

Definition

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

Overloads

ExecuteScalarAsync()

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

Invokes ExecuteScalarAsync(CancellationToken) with CancellationToken.None.

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.

Remarks

For more information about asynchronous programming, see Asynchronous Programming.

ExecuteScalarAsync()

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

Invokes ExecuteScalarAsync(CancellationToken) with CancellationToken.None.

public:
 System::Threading::Tasks::Task<System::Object ^> ^ ExecuteScalarAsync();
public System.Threading.Tasks.Task<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

Task<Object>

A task representing the asynchronous operation.

Exceptions

An error occurred while executing the command.

Remarks

For more information about asynchronous programming, see Asynchronous Programming.

See also

Applies to

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);
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>
Public Overridable Function ExecuteScalarAsync (cancellationToken As CancellationToken) As Task(Of Object)

Parameters

cancellationToken
CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<Object>

A task representing the asynchronous operation.

Exceptions

An error occurred while executing the command.

Remarks

For more information about asynchronous programming, see Asynchronous Programming.

See also

Applies to