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:
Open the Visual Studio .NET IDE.
Create a new Visual C# Console Application named
CreateStronglyTypedDataSet.Right-click on the project in Solution Explorer and click Add → New Item to open the Add New Item dialog. Select
DataSetfrom the Visual Studio installed templates. Name theDataSetAdventureWorks.xsd. The completed dialog is shown in Figure 2-16. Click the Add button to create theDataSetand close the dialog.The
DataSetis added to Solution Explorer and the DataSet Designer is opened.
Figure 2-16. Add New Item dialog
Next, add database objects to the
DataSetusing a Database Connection. If you do not already have anAdventureWorksDatabase 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 theAdventureWorksdatabase, leave log on mode ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access