How to: Provide a Value to a Query Parameter
For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.
By binding a parameter to a field in a screen, you can enable users to provide the value of a query parameter.
Users can provide a value either directly or implicitly. They can type the value directly into a text box or they can select an item from a related list on the screen. For example, to view a list of sales orders, a user can type the ID number of a customer or select a customer from a customer list.
To enable users to type a value, bind the parameter to a field in the screen. To enable users to provide the value implicitly, bind the parameter to a field in a list that appears on the screen. For example, you might bind the CustomerID
parameter of an Orders
query to the CustomerID
field of a Customers list.
For a related video demonstration, see How Do I: Pass a Parameter into a Screen from the Command Bar in a LightSwitch Application?.
To Bind a Query Parameter to a Field
Create a query that accepts a parameter (for example: the ID of a customer). For more information, see How to: Design a Query by Using the Query Designer.
Add the query to the Screen Content Tree. For more information, see How to: Design a Silverlight Screen by Using the Screen Designer.
Add a local field to the screen. For more information, see How to: Add a Local Property to a Silverlight Screen.
In the Screen Members List of the Screen Designer, select the parameter of the query.
On the View menu, click Properties Window.
Select the Parameter Value text box.
Select or type the name of the local field.
To Bind a Query Parameter to a Field in a List
Create a query that accepts a parameter (for example: the ID of a customer). For more information, see How to: Design a Query by Using the Query Designer.
Add the query to the Screen Content Tree. For more information, see How to: Add Data to a Screen.
Add a second query to the Screen Content Tree. Make sure that the entity returned by this query contains a field that matches the parameter of the first query.
For example, if the first query accepts a customer ID as a parameter, make sure that the second query returns an entity that contains a customer ID field.
In the Screen Members List of the Screen Designer, select the parameter of the query.
On the View menu, click Properties Window.
Select the Parameter Value text box.
Select or type the fully qualified name of a field from the second query (for example: CustomerList.SelectedItem.CustomerID).
Next Steps
To learn how provide parameter values to a query by using code, see How to: Retrieve Data from a Query by Using Code.
See Also
Queries: Retrieving Information from a Data Source
How to: Add, Remove, and Modify a Query
Walkthrough: Designing a Screen
How to: Design a Query by Using the Query Designer
How to: Retrieve Data from a Query by Using Code