Dela via


How to: Add Global Queries to a Dataset

Global queries are SQL queries that return either a single (scalar) value or no value. Typically, global functions perform database operations such as inserts, updates, deletes, and the aggregating of information, such as returning a count of customers in a table or the total charges for all items in a particular order.

You add global queries by running the TableAdapter Query Configuration Wizard from within the Dataset Designer.

Note

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 global query to a dataset

  1. Open a dataset in the Dataset Designer. For more information, see How to: Open a Dataset in the Dataset Designer.

  2. Drag a Query from the DataSet tab of the Toolbox onto an empty area of the Dataset Designer.

    The TableAdapter Query Configuration Wizard opens.

  3. Choose a connection for the query to use. You can either choose one from the list or create a new connection. If you create a new connection, you will have the option to save it to the application configuration file. For more information, see How to: Save a Connection String.

  4. Choose whether to use SQL statements or stored procedures.

  5. Choose the stored procedure to use or, on the Choose a Query Type page of the wizard, choose the type of query you want and then click Next.

  6. Provide a query that performs the desired task, for example, SELECT COUNT(*) AS CustomerCount FROM Customers.

    Note

    Dragging a query directly onto the Dataset Designer creates a method that will only return a scalar (single) value. While the query or stored procedure you select may return more than a single value, the method created by the wizard will only return a single value. For example, the query might return the first column of the first row of the returned data.

  7. Complete the wizard; the query is added to the Dataset Designer. For information on running the query, see How to: Execute TableAdapter Queries.

See Also

Tasks

How to: Create TableAdapters

How to: Create TableAdapter Queries

How to: Connect to Data in a Database

How to: Navigate Data with the Windows Forms BindingNavigator Control

Walkthrough: Displaying Data on a Form in a Windows Application

Concepts

Displaying Data Overview

TableAdapter Overview

Dataset Designer

Data Sources Overview

Other Resources

Validating Data