Using the ODBC Query Component
These steps describe how to return data from the Microsoft SQL Chinook database and display the data in a datagrid on a Windows form using an ODBCQuery component.
Create a Windows form with a button, text box,
and data grid. Here is an example:
Add the TableView component to the Windows form. It is displayed in the Component tray.
Add an automation to the solution.
Add the ODBCQuery component to the automation. It is displayed on the Global tab of the Component tray as required.
Browse the ConnectionString property for the
query. Select the connection type and specify the connection parameters
for the datasource. Examples of the Data Link setup dialog tabs are
shown here:
Click the Test Connection button in the Data Link Properties dialog to make sure you have a valid connection to the data source.
Once you receive validation of the connection, click OK to save the settings and return to Studio. The ConnectionString property will be populated based on the settings you chose in the Data Link Properties window. Here is an example: ConnectionString: Dsn=MS Sql Server;persist security info=False;uid=User.
Make sure Text is selected as the CommandType.
Browse the CommandText property to open the
SQL Command Text window. Enter the following SQL statement: "select * from Customers where Country
=?" Here is an example:
Click OK to close the SQL Command Text dialog once you have entered the SQL statement.
Verify that the ReturnType property is set to ReturnsRows.
Browse the Parameters property to open the OdbcParameter Collection Editor. Set the Size property to 99 and the value to USA.
Click OK to save the parameter information and close the editor.
Click the Test Query link in the Properties grid. Note that you must test the query for the query parameters to be fully defined in the project. If you run the project without testing the query in Studio, an error is thrown. Click the Test Query link to test the query with the parameters.
When prompted to execute the SQL command against the connected database, click Yes.
An information box indicates that the query executed successfully if you defined your ConnectionString, CommandText, and Parameters correctly. Click OK to close the information box.
Drag the Execute method for the ODBCQuery to the automation. Note that a parameter is exposed for input of the where clause parameter.
Connect the solution components as shown in
the following automation:
Return to the Windows form in the Designer and select the TableView object.
Click on the TableProvider property to expose
available data sources. The query should be listed here as follows:
Select the oDBCQuery1 component as the TableProvider. For more information, see TableView Component.
Select the DataGrid component from the toolbox. Click the DataSource property and select the TableView1 object as the data provider. The data you retrieved when you tested the query displays in the DataGrid.
Save and run your solution.
Enter a Country name in the text box and click
Get Data. The ODBCQuery returns data for the country you selected.
Privacy | Trademarks | Terms of Use | Feedback
Updated: 18 June 2020
© 2016 - 2020 Pegasystems Inc. Cambridge, MA All rights reserved.