Creating a Data Source
Creating an application that relies on a stored procedure begins as any other database application. You create the application project, display the Data Sources window by choosing Data > Show Data Sources, and then click Add New Data Source in the Data Source window. Following the configuration steps creates a connection to your database. Normally, you’ll configure the data sources you need immediately when you get to the Choose Your Database Objects page of the wizard, as shown in Figure 1. Simply select the objects that you want, as shown in the figure.
Figure 1 Choose the data objects you want to use in your project, or add them later.
Invariably, however, you’ll leave out an important data object, which is where part of the drag-and-drop element of this article comes into play. It’s easy to add new objects to your dataset as needed. Highlight the connection you want to use in the Data Sources window, and click Edit DataSet with Designer at the top of the window. You’ll see a designer window similar to the one shown in Figure 2.
Figure 2 Use the designer to make changes to the dataset.
You can add new objects using either of two methods:
- Drag-and-drop them from Server Explorer onto the designer. This technique is easiest, and you should use it whenever possible to save time. It results in a default object setup, which works, for the most part—but not always, as you’ll see when working with the managed stored procedure in this article.
- Right-click the designer to open the context menu, choose Add, and select an object type. For example, Figure 2 shows a TableAdapter, which is the most common object you’ll use. You can also create DataTable, Query, and Relation objects.
No matter how you add the object, it appears in the Data Sources window. This window provides the means for configuring data sources, and then dragging-and-dropping them onto your project.