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.
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.
To add a global query to a dataset
Open a dataset in the Dataset Designer. For more information, see.
Drag a Query from the DataSet tab of the Toolbox onto an empty area of the Dataset Designer.
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.
Choose whether to use SQL statements or stored procedures.
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.
Provide a query that performs the desired task, for example, SELECT COUNT(*) AS CustomerCount FROM Customers.
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.
Complete the wizard; the query is added to the Dataset Designer. For information on running the query, see.