Share via


SqlBatch.ExecuteScalarAsync(CancellationToken) Method

Definition

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

public override System.Threading.Tasks.Task<object> ExecuteScalarAsync (System.Threading.CancellationToken cancellationToken = default);
override this.ExecuteScalarAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<obj>
Public Overrides Function ExecuteScalarAsync (Optional cancellationToken As CancellationToken = Nothing) As Task(Of Object)

Parameters

cancellationToken
CancellationToken

A token to cancel the asynchronous operation.

Returns

The first column of the first row in the first result set.

Exceptions

An error occurred while executing the batch.

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

Remarks

This method benefits from ExecuteScalarAsync(CancellationToken), and all the expected exceptions of that method also apply here. 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.

Applies to