I am trying to use the SQLDataSource component that has been added to the Winforms package in the last version of Devexpress to make it work as a query manager. Our idea is to provide the SQLDataSource component with the connection information and then open the Query Manager to design queries for the selected connection and then fill a XtraGrid with the results.
I do something like this:
1 - Create SQLDatasource and assign a connection (I provide the parameters)
2 - Open Query Manager and retrieve the query[C#]
Dim dataadapter As SqlDataSource = New SqlDataSource Dim con As SqlDataConnection = New SqlDataConnection("connection", params) dataadapter.ConnectionParameters = params dataadapter.ConnectionName = "connection" dataadapter.Connection.CreateDataConnectionParameters() dataadapter.Connection.CreateConnectionString()[VB.NET]
DevExpress.DataAccess.UI.Sql.SqlDataSourceUIHelper.ManageQueries(dataadapter) dataadapter.Fill() For Each q As TableQuery In dataadapter.Queries dataadapter.RebuildResultSchema() mGeneratedQuery = q.GetSql(dataadapter.Connection.GetDBSchema()) Return True Next
This is working ok, my problem is that I would like to allow to store the SQL querys and then load them in the Query Manager so the user can choose them in order to load the Grid or create new ones if he wants. I am able to load the queries with the following code:
What we need now is the following: We need to allow the end-user to select the query we want to load the grid with, when I close the query manager I have a query list but I have no way to know wich one has selected the user. Is there a way to access the query manager dialogs or capture some kind of event to make this possible?[VB.NET]
For i As Integer = 0 To mQuerysObj.QueryList.Count - 1 If CType(mQuerysObj.QueryList(i), QueryMenuPoint).databaseID = selectedDB.mIdBBDD Then Dim tQuery As New CustomSqlQuery() tQuery.Name = CType(mQuerysObj.QueryList(i), QueryMenuPoint).queryName tQuery.Sql = CType(mQuerysObj.QueryList(i), QueryMenuPoint).query dataadapter.Queries.Add(tQuery) End If Next
I attach a file with the selection screen of the query manager. My need is that when I click Ok in that dialog I can know what query was selected.
Note that the "ManageQueries" dialog was designed to edit the queries of the SqlDataSource, it was not created for the query selection. So there is no way to get the selected query from this dialog. I suggest creating your own dialog for this purpose. For example, put a ListBox control for the query selection in this dialog and populate this ListBox with the queries that are added to the SqlDataSource.Queries collection. Let us know if you have any further questions regarding this.