Creating a Parameterized Query in LightSwitch
This lesson shows how to create a parameterized query in a LightSwitch application.
A parameterized query determines what data to return by evaluating one or more values when the application runs. For example, a parameterized query might return a list of products that fall into a certain category that a parameter identifies. You can set the parameter programmatically, but most applications use parameters that reflect values that a user sets.
To create a parameterized query
In Solution Explorer, choose the Products.lsml node.
On the menu bar, choose Project, Add Query.
The Query Editor opens.
In the Properties window, name the query ProductsByCategory.
In the Query Designer, choose the Add Filter link.
In the first list, choose Where.
In the second list, choose Category.CategoryID.
In the third list, choose = (equals).
In the fourth list, choose Parameter.
In the final list, choose Add New.
A pParameter that's named CategoryID, of type Integer is created and added to the Parameters section of the Query Editor.
This lesson showed how to create a parameterized query that returns a subset of products. At run time, a CategoryID box is provided so that a user can specify a numeric value for the CategoryID parameter. For example, if the user specifies 1 in the box, all products in the Beverages category will be returned. If the user specifies 2, Condiments will be returned.
The parameter value can be typed into a text box or selected from a list. It can also be provided by another entity on a screen. For example, when a product is selected on a screen, you could use its CategoryID as a parameter to return all other products in the same category.
In the next lesson, you’ll learn how to use the parameterized query that you just created on a screen.
Next lesson: Using a Parameterized Query on a LightSwitch Screen