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
DataSet
from the Visual Studio installed templates. Name theDataSet
AdventureWorks.xsd. The completed dialog is shown in Figure 2-16. Click the Add button to create theDataSet
and close the dialog.The
DataSet
is added to Solution Explorer and the DataSet Designer is opened.Figure 2-16. Add New Item dialog
Next, add database objects to the
DataSet
using a Database Connection. If you do not already have anAdventureWorks
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 theAdventureWorks
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.