- Using Tables Isnt Safe
- Choosing a Stored Procedure Type
- Creating a Data Source
- Using Standard Stored Procedures
- Creating an Application to Use the Standard Stored Procedure
- Creating a Managed Project
- Creating an Application by Using a Stored Procedure
- Bottom Line
Creating an Application to Use the Standard Stored Procedure
Creating an object in the dataset makes it available for use in a project. This example uses a simple form to display the stored procedure. When you select a project tab containing a form, you can configure both tables and individual columns. A table can have either a DataGrid or a Details view, in most cases. Depending on the data type of a particular field, you can have one of many options, as shown in Figure 5. Everything is individually configurable, and you should perform this configuration before the next step in the process.
Figure 5 Use simple configuration choices to change how Visual Studio creates display code for the database object.
I decided to use a Details view for this portion of the example, and changed all of the data fields to labels, since the example doesn’t allow editing. You can set the ContactTitle field to None since you don’t need it in this example. (You already know the contact title, so there isn’t any reason to display it.) Once you make any configuration changes, drag-and-drop the object onto the application form. Visual Studio automatically draws all of the required controls for you, adds any required code, and makes any required property changes. In many cases, all you need to do is reposition some of the display elements and make a few cosmetic changes. Figure 6 shows the output from this example.
Figure 6 Let Visual Studio do the heavy lifting for you to create standardized displays.
The central premise of making this kind of programming work is getting the stored procedure right. If you find that you’re writing a lot of extra code when using this technique, it’s more than likely a problem with the stored procedure. Make sure that any stored procedure you use actually produces the results you need.