
When defining a TableAdapter or adding new methods, the TableAdapter s wizard makes it just as easy to create new stored procedures or use existing stored procedures as it does to use ad-hoc SQL statements. In my own work I favor stored procedures over ad-hoc SQL statements, but chose to use ad-hoc SQL statements to simplify the earlier tutorials. Others ardently prefer ad-hoc SQL statements for their flexibility.


Many developers and database administrators, however, prefer stored procedures over ad-hoc SQL statements for security, maintainability, and updatability reasons. The TableAdapters in our architecture use ad-hoc SQL statements. The SQL commands executed by the TableAdapters can be either ad-hoc SQL statements, such as SELECT columnList FROM TableName, or stored procedures. This includes populating the DataTables with data, executing queries that return scalar data, and inserting, updating, and deleting records from the database. The DataTables represent the logical entities in the system while the TableAdapters interface with the underlying database to perform the data access work. As discussed in the Creating a Data Access Layer tutorial, Typed DataSets consist of strongly-typed DataTables and TableAdapters. The Data Access Layer (DAL) for these tutorials uses Typed DataSets. In this tutorial we learn how to have the TableAdapter Wizard generate new stored procedures for us.

An alternative approach is to use stored procedures, where the SQL statements are pre-defined at the database. In earlier tutorials we have created SQL statements in our code and passed the statements to the database to be executed.
