All docs
V21.1
21.2 (EAP/Beta)
21.1
20.2
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Session.ExecuteScalarAsync(String, String[], QueryParameterCollection, CancellationToken) Method

Asynchronously executes the specified SQL query and returns the first column of the first row in the result set returned by the query.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v21.1.dll

Declaration

public Task<object> ExecuteScalarAsync(
    string sql,
    string[] parameterNames,
    QueryParameterCollection parameters,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

Name Type Description
sql String

Specifies an SQL statement.

parameterNames String[]

Specifies parameter names.

parameters QueryParameterCollection

Specifies query parameter values.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken

null

A CancellationToken object that delivers a cancellation notice to the running operation.

Returns

Type Description
Task<Object>

A Task<TResult> that returns the first column of the first row in the query’s result set. A null reference (Nothing in Visual Basic) if the result set does not contain columns. DBNull.Value if the first column does not contain a value.

Remarks

Use the ExecuteScalarAsync method to query data stores for a single or aggregate value, without having to retrieve a result set.

Use QueryParameterCollection to pass strongly-typed parameters. See examples here: Always Encrypted (SQL Server only).

To learn more about executing SQL statements in XPO, refer to Direct SQL Queries.

Note

The ExecuteScalarAsync method sends statements directly, so the correct statement syntax and parameter names format depends on a particular database server.

See Also