views:

518

answers:

3

Hi,

Can someone tell me why I would use a query adapter within the dataset designer instead of adding queries to the table adapter?

Regards

+4  A: 

Sometimes your queries do not need to be associated with an actual DataTable. Perhaps you have a Query that is logically grouped within your DataSet, but has no real backing store.

For Instance, suppose you wanted to call a stored procedure that safely deletes all associated records for a given customer:

proc_DeleteAllAssociatedCustomerRecords

This really doesn't belong to any one particular entity as it might span multiple tables, but still belongs in your CustomerDataSet.

Josh
+1  A: 

In addition to Josh's answer, I'd add that it's useful when you have a select query that has a different schema than the rest of a table. Say you want just id & name from a table for a dropdown, and that table has a lot of fields.

Tim Hoolihan
+1  A: 

Unlike standard data adapters, TableAdapters can contain multiple queries to fill their associated data tables. You can define as many queries for a TableAdapter as your application requires, as long as each query returns data that conforms to the same schema as its associated data table. This enables loading of data that satisfies differing criteria.

In addition to queries that return data of the same schema as the TableAdapter's data table, you can add queries that return scalar (single) values. For example, creating a query that returns a count of customers (SELECT Count(*) From Customers) is valid for a CustomersTableAdapter even though the data returned does not conform to the table's schema.

http://msdn.microsoft.com/en-us/library/bz9tthwx(VS.80).aspx

Robert Harvey