Search Criteria Builder Dialog Box

Complete this dialog box to add a new query (typically a parameterized query) to an existing data-bound form in your Windows application. This includes adding a new query to the selected table, and adding controls for users to input any parameter values on the form (a button to execute the query is also added to the form).

A parameterized query returns data that meets the conditions of a WHERE clause in the query. For example, you can parameterize a customer list to display only customers in a certain city by adding WHERE City = @City to the end of the SQL statement that returns a list of customers. The WHERE clause defines a condition to be met when executing a query. SELECT * FROM Customers returns all records in the Customers table, whereas SELECT * FROM Customers WHERE City = @City only returns records in which the City column equals the value of the @City parameter. Add a WHERE clause that makes sense to the end of your query.

Some typical WHERE clauses:

SELECT * FROM Employees WHERE CompanyName like @CompanyName
SELECT * FROM Employees WHERE (LastName = @Lname) and (FirstName = @Fname)

Note

The syntax for parameter placeholders varies depending on the data source. This example shows placeholders for a SQL Server data source (@paramname). Use question mark (?) placeholders for System.Data.OleDb and System.Data.Odbc parameters (WHERE CompanyName like ?).

This dialog box appears when Add Query is chosen on a smart tag or from the Data menu.

Using this dialog box, you can:

User Interface Element List

  • Select data source table
    Select the table to add the query to from the drop-down list of available tables in your project.

  • Select a parameterized query to load data
    Select a new or existing parameterized query.

  • New query name
    Type a name for the new parameterized query.

  • Existing query name
    Select a query from the drop-down list of available queries for the selected data source table.

  • Query Text
    Enter the SQL statement that will execute when the button is clicked.

    Note

    The wizard provides the Query Builder, a visual tool for creating SQL queries.

  • Query Builder
    Opens the Query Builder, a visual tool for creating SQL queries. For more information, see Query and View Designer Tools.

See Also

Tasks

Walkthrough: Displaying Data on a Windows Form

How to: Add a Parameterized Query to a Windows Forms Application

Walkthrough: Creating a Windows Form to Search Data

Concepts

Binding Windows Forms Controls to Data in Visual Studio

Preparing Your Application to Receive Data

Fetching Data into Your Application

Binding Controls to Data in Visual Studio

Editing Data in Your Application

Validating Data

Saving Data

Other Resources

Connecting to Data in Visual Studio