Edit

Share via


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()

Source:
DbCommand.cs
Source:
DbCommand.cs
Source:
DbCommand.cs

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

A task representing the asynchronous operation.

Exceptions

An error occurred while executing the command.

Remarks

For more information about asynchronous programming, see Asynchronous Programming.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by ExecuteScalar().

See also

Applies to

ExecuteScalarAsync(CancellationToken)

Source:
DbCommand.cs
Source:
DbCommand.cs
Source:
DbCommand.cs

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

A task representing the asynchronous operation.

Exceptions

An error occurred while executing the command.

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

Remarks

For more information about asynchronous programming, see Asynchronous Programming.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by ExecuteScalar().

See also

Applies to