Back to Devexpress

Session.ExecuteScalar(String, QueryParameterCollection) Method

xpo-devexpress-dot-xpo-dot-session-dot-executescalar-x28-system-dot-string-devexpress-dot-xpo-dot-db-dot-queryparametercollection-x29.md

latest2.9 KB
Original Source

Session.ExecuteScalar(String, QueryParameterCollection) Method

SECURITY-RELATED CONSIDERATIONS

This method executes a raw SQL query string. Always validate, sanitize, or parameterize externally supplied SQL query strings to prevent unauthorized access to sensitive information.

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.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public object ExecuteScalar(
    string sql,
    QueryParameterCollection parameters
)
vb
Public Function ExecuteScalar(
    sql As String,
    parameters As QueryParameterCollection
) As Object

Parameters

NameTypeDescription
sqlString

Specifies an SQL statement.

| | parameters | QueryParameterCollection |

Specifies query parameter values.

|

Returns

TypeDescription
Object

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 ExecuteScalar 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).

The connection provider automatically generates sequential parameter names (p0, p1, p2 …). To specify custom parameter names, use the overloaded ExecuteScalar(String, String[], QueryParameterCollection) method.

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

Note

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

See Also

Session Class

Session Members

DevExpress.Xpo Namespace