Using a Parameterized Query on a Screen
In this lesson, you will learn how to use a parameterized query on a screen to filter data.
In the last lesson, you created a query to filter products based on a CategoryID parameter. At run time, this parameter can be used to apply the filter to another entity that contains a CategoryID field. For example, you can use the parameterized query to display a list of products that match the category of a selected product in a list on the screen.
The parameter value can be supplied as a property in the Screen Designer at design time or by the user at run time. In this example, you will assign the value at design time.
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.
To add a parameterized query to a screen
In Solution Explorer, double-click the CurrentProductList screen node.
In the Screen Designer, click the Add Data Item toolbar button.
The Add Data Item dialog box appears.
In the Add Data Item dialog box, click Query.
In the Name column, select NORTHWINDDATA1.ProductsByCategory, and then click OK.
A ProductsByCategoryCollection node is added to the left pane.
Under the Query Parameters node, select CategoryID.
In Properties window, select Parameter Binding and type CurrentProducts.SelectedItem.CategoryID.
In the Screen Designer, select the (RIGHT COLUMN) Vertical Stack | Details Column node.
Click Add and select ProductsByCategory from the drop-down list.
A new DataGrid | ProductsByCategory node appears in the screen content tree.
Press F5 to run the application and view the results.
When you open the CurrentProductList screen, notice that all products that have the same CategoryID as the currently selected product are displayed in the new grid.
In this procedure, you used the parameterized query that you created in the last lesson to display a list of products. The query was added to an existing screen, the CurrentProductList screen. The Parameter Value property of the query specifies the CategoryID value from the existing ProductCollection on the screen and supplies the parameter at run time. As a result, a list of products that have a matching CategoryID is displayed every time a product is selected in the ProductCollection list.
In the next set of lessons, you will learn how to work with menus and commands.
Next lesson: Creating Menus and Commands