2.16. Creating a Strongly Typed DataSet

Problem

You want to create a strongly typed object wrapper around a DataSet.

Solution

Use either the Visual Studio .NET IDE or a command line approach to create a strongly typed DataSet. The solution shows both techniques in the following subsections.

Using the Visual Studio .NET IDE to generate a typed DataSet

The first and easiest method uses Visual Studio .NET following these steps:

  1. Open the Visual Studio .NET IDE.

  2. Create a new Visual C# Console Application named CreateStronglyTypedDataSet.

  3. Right-click on the project in Solution Explorer and click Add → New Item to open the Add New Item dialog. Select DataSet from the Visual Studio installed templates. Name the DataSet AdventureWorks.xsd. The completed dialog is shown in Figure 2-16. Click the Add button to create the DataSet and close the dialog.

    The DataSet is added to Solution Explorer and the DataSet Designer is opened.

    Add New Item dialog

    Figure 2-16. Add New Item dialog

  4. Next, add database objects to the DataSet using a Database Connection. If you do not already have an AdventureWorks Database Connection, create one: Open Server Explorer by selecting View → Server Explorer from the main menu. Rightclick on the Data Connections node and select Add Connection from the context menu to Open the Add Connection dialog. In the Add Connection dialog, select the SQL Server with the AdventureWorks database, leave log on mode ...

Get ADO.NET 3.5 Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.