Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Accessing Data
TableAdapters
 How to: Create Parameterized TableA...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Data Access in Client and Middle-Tier Programming
How to: Create Parameterized TableAdapter Queries

A parameterized query returns data that meets the conditions of a WHERE clause within 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. For more information, see Parameter Queries.

You create parameterized TableAdapter queries in the Dataset Designer, or during creation of data-bound forms in a Windows application with the Parameterize Data Source command on the Data menu. The Parameterize Data Source command also creates controls on your form to input the parameter values and execute the query. For more information, see Search Criteria Builder Dialog Box.

NoteNote:

When constructing a parameterized query, use the parameter notation specific to the database you are coding against. For example, Access and OleDb data sources use the question mark '?' to denote parameters, so the WHERE clause would look like this: WHERE City = ?.

NoteNote:

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 create a parameterized query in the Dataset Designer

  • Create a new TableAdapter, adding a WHERE clause with the desired parameters to the SQL statement. For more information, see How to: Create TableAdapters.

    -or-

  • Add a query to an existing TableAdapter, adding a WHERE clause with the desired parameters to the SQL statement. For more information, See How to: Create TableAdapter Queries.

To create a parameterized query while designing a data-bound form

  1. Select a control on your form that is already bound to a dataset. For more information, see Displaying Data Overview.

  2. On the Data menu, click Add Query.

  3. Complete the Search Criteria Builder dialog box, adding a WHERE clause with the desired parameters to the SQL statement. For more information, see Search Criteria Builder Dialog Box.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker