Share 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

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Customizing Development Settings in Visual Studio.

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 and Edit Connection Strings.

  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 Windows Form

Concepts

Binding Windows Forms Controls to Data in Visual Studio

TableAdapter Overview

Creating and Editing Typed Datasets

Data Sources Overview

Validating Data