ExecuteScalarAsync(CancellationToken cancellationToken)
This method returns a Task-based asynchronous version of OracleCommand.ExecuteScalar(), which returns the first column of the first row in the result set returned by the query.
Declaration
// C# public override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken);
Parameters
cancellationToken - The input cancellation token which can be used by the application to cancel the task before command timeout occurs.
Return Value
Task<object> object representing the asynchronous operation immediately without blocking the calling thread for the whole duration of the query execution.
Implements
DbCommand
Exceptions
InvalidOperationException - The command cannot be executed.
Example
using Oracle.ManagedDataAccess.Client;
using System.Threading;
namespace AsyncApp
{
class AsyncDemo
{
static async Task Main()
{
string connectionString = "User Id=HR; Password=<PASSWORD>; Data Source=oracle;";
OracleConnection oc = new OracleConnection(connectionString);
await oc.OpenAsync(CancellationToken.None);
OracleCommand cmd = oc.CreateCommand();
cmd.CommandText = "select * from demo_table";
var value = await cmd.ExecuteScalarAsync(CancellationToken.None);
}
}
}