Back to Devexpress

SqlDataSource.Queries Property

corelibraries-devexpress-dot-dataaccess-dot-sql-dot-sqldatasource.md

latest6.9 KB
Original Source

SqlDataSource.Queries Property

Provides access to the collection of queries defined for the SqlDataSource.

Namespace : DevExpress.DataAccess.Sql

Assembly : DevExpress.DataAccess.v25.2.dll

NuGet Package : DevExpress.DataAccess

Declaration

csharp
[LocalizableCategory(DataAccessStringId.PropertyGridDataCategoryName)]
public SqlQueryCollection Queries { get; }
vb
<LocalizableCategory(DataAccessStringId.PropertyGridDataCategoryName)>
Public ReadOnly Property Queries As SqlQueryCollection

Property Value

TypeDescription
SqlQueryCollection

A SqlQueryCollection object.

|

Remarks

The code sample below demonstrates how to create a custom query and add it to the Queries collection.

csharp
using DevExpress.DataAccess;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
// ...

private SqlDataSource BindToData() {
    // Create a data source with the required connection parameters.   
    Access97ConnectionParameters connectionParameters =
    new Access97ConnectionParameters("../../Data/nwind.mdb", "", "");
    SqlDataSource ds = new SqlDataSource(connectionParameters);

    // Create an SQL query to access the Products table.
    CustomSqlQuery query = new CustomSqlQuery();
    query.Name = "customQuery1";
    query.Sql = "SELECT * FROM Products";

    // Add the created query to the collection.
    ds.Queries.Add(query);
    return ds;
}
vb
Imports DevExpress.DataAccess
Imports DevExpress.DataAccess.ConnectionParameters
Imports DevExpress.DataAccess.Sql
' ...

Private Function BindToData() As SqlDataSource
    ' Create a data source with the required connection parameters.   
    Dim connectionParameters As New Access97ConnectionParameters("../../Data/nwind.mdb", "", "")
    Dim ds As New SqlDataSource(connectionParameters)

    ' Create an SQL query to access the Products table.
    Dim query As New CustomSqlQuery()
    query.Name = "customQuery1"
    query.Sql = "SELECT * FROM Products"

    ' Add the created query to the collection.
    ds.Queries.Add(query)
    Return ds
End Function

Note that queries are executed in the order they have in the Queries collection.

The following code snippets (auto-collected from DevExpress Examples) contain references to the Queries property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-grid-edit-the-sqldatasource-connection-and-query-at-runtime/CS/T292798/Form1.cs#L26

csharp
private void btEditQuery_Click(object sender, EventArgs e) {
    SqlDataSourceUIHelper.EditQuery(sqlDataSource1.Queries["DefaultQuery"]);

winforms-dashboard-pass-dashboard-parameters-to-custom-sql-query-in-code/CS/Dashboard_ParametersAndCustomSQL/Form1.cs#L22

csharp
DashboardSqlDataSource dataSource = (DashboardSqlDataSource)dashboard.DataSources[0];
CustomSqlQuery salesPersonQuery = (CustomSqlQuery)dataSource.Queries[0];
salesPersonQuery.Parameters.Add(new QueryParameter("startDate", typeof(Expression),

winforms-dashboard-designer-merge-dashboards-to-tabs/CS/DashboardMerger/ParametersMerger.cs#L55

csharp
static void UpdateSqlDataSourceParameters(DashboardSqlDataSource sqlDataSource, string originalNamePattern, string copyNamePattern) {
    foreach(SqlQuery query in sqlDataSource.Queries) {
        foreach(QueryParameter parameter in query.Parameters) {

query-builder-use-in-asp-net-core-application/CS/AspNetCoreQueryBuilderApp/Controllers/HomeController.cs#L67

csharp
var dataSource = SerializationService.SqlDataSourceFromByteArray(existingDataSource.SerializedDataSource);
var queryBuilderModel = queryBuilderClientSideModelGenerator.GetModel(existingDataSource.ConnectionName, (SelectQuery)dataSource.Queries[0]);
return new QueryBuilderControlModel {

winforms-dashboard-pass-dashboard-parameters-to-custom-sql-query-in-code/VB/Dashboard_ParametersAndCustomSQL/Form1.vb#L23

vb
Dim dataSource As DashboardSqlDataSource = DirectCast(dashboard.DataSources(0), DashboardSqlDataSource)
Dim salesPersonQuery As CustomSqlQuery = CType(dataSource.Queries(0), CustomSqlQuery)
salesPersonQuery.Parameters.Add(New QueryParameter("startDate", GetType(Expression), New Expression("[Parameters.yearParameter] + '/01/01'")))

winforms-dashboard-designer-merge-dashboards-to-tabs/VB/DashboardMerger/ParametersMerger.vb#L60

vb
Private Shared Sub UpdateSqlDataSourceParameters(ByVal sqlDataSource As DashboardSqlDataSource, ByVal originalNamePattern As String, ByVal copyNamePattern As String)
    For Each query As SqlQuery In sqlDataSource.Queries
        For Each parameter As QueryParameter In query.Parameters

See Also

SqlDataSource Class

SqlDataSource Members

DevExpress.DataAccess.Sql Namespace