DbCommand.ExecuteScalarAsync Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Implements the asynchronous version of ExecuteScalar(), but returns a Task synchronously, blocking the calling thread.
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 |
For more information about asynchronous programming, see Asynchronous Programming.
- 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
.NET 9 וגירסאות אחרות
מוצר | גירסאות |
---|---|
.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 |
- 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
.NET 9 וגירסאות אחרות
מוצר | גירסאות |
---|---|
.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 |
משוב של .NET
.NET הוא פרויקט קוד פתוח. בחר קישור כדי לספק משוב: