The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Session.ExecuteQuery(String, Object[]) Method

Executes the specified SQL query and returns a result set.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v19.2.dll

Declaration

public SelectedData ExecuteQuery(
    string sql,
    object[] parameterValues
)
Public Function ExecuteQuery(
    sql As String,
    parameterValues As Object()
) As SelectedData
public SelectedData ExecuteQuery(
    string sql,
    object[] parameterValues
)
Public Function ExecuteQuery(
    sql As String,
    parameterValues As Object()
) As SelectedData

Parameters

Name Type Description
sql String

A String value that specifies a parameterized SQL query.

parameterValues Object[]

An array of objects specifying parameters to pass to the database server along with the query.

Parameters

Name Type Description
sql String

A String value that specifies a parameterized SQL query.

parameterValues Object[]

An array of objects specifying parameters to pass to the database server along with the query.

Returns

Type Description
SelectedData

A SelectedData object, specifying the query's result set.

Returns

Type Description
SelectedData

A SelectedData object, specifying the query's result set.

Remarks

Use ExecuteQuery to query data stores for result sets. You can visualize result sets via the XPDataView. To learn how to access the resulting data, refer to How to: Access Data in SQL Query Results.

The example below demonstrates how to use this method. Here, session is the Session instance.

using DevExpress.Xpo.DB;
// ...
SelectedData data = GetEmployeesSimpleData();
// ...
public SelectedData GetEmployeesSimpleData() {
    const string queryString =
        @"SELECT EmployeeID, (FirstName + ' ' + LastName) as Name, City, Country 
        FROM [Northwind].[dbo].[Employees]
        WHERE City = @p1";
    return session.ExecuteQuery(queryString, new object[] { "London" });
}

Note that a format of parameter names in a SQL statement depends on the ADO.NET provider and database you use.

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

Note

The ExecuteQuery method sends queries directly, so the correct query syntax depends on a particular database server.

See Also