How to: Create TableAdapter Queries

TableAdapter queries are SQL statements or stored procedures that your application can execute against a database.

Add as many queries to a TableAdapter as your application requires. TableAdapter queries appear as methods on a TableAdapter. When you create a query called FillByCity that takes a parameter representing the city value, the query is added to the TableAdapter. It is added as a typed method that takes the correct type of parameter as an argument — in this case a string representing the city value. You call the TableAdapter query just like any method on any object. For example, the following code executes the FillByCity query and fills the Customers table with all customers with a city value of Seattle:

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To add a query to a TableAdapter in the Dataset Designer

Drag a Query from the DataSet tab of the Toolbox onto a table on the designer.

The TableAdapter Query Configuration Wizard opens.

Complete the wizard; the query is added to the TableAdapter.

Create a Query Directly on a Form in Your Windows Application

If you have an instance of a TableAdapter on your form you can add a query using the Search Criteria Builder Dialog Box, which adds a ToolStrip control to the form that accepts any input parameters required by the query, as well as a button to run the query.