O'Reilly logo

ADO.NET Cookbook by Bill Hamilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.3. Creating a Strongly Typed DataSet

Problem

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

Solution

Use one of the three techniques shown in the discussion to create a strongly typed DataSet using either the Visual Studio .NET IDE or a command line approach.

Discussion

A strongly typed DataSet is a collection of classes that inherit from and extend the DataSet, DataTable, and DataRow classes, and provide additional properties, methods, and events based on the DataSet schema. You can use all of the functionality in classes from which the strongly typed classes inherit in the same way as with untyped classes.

A strongly typed DataSet class contains, in addition to a single class extending the DataSet class, three classes for each table in the DataSet extending each of the DataTable, DataRow, and DataRowChangeEvent classes. This recipe describes these classes and discusses their commonly used methods and properties.

There is a class named TableNameDataTable for each table in the strongly typed DataSet. It has the base class DataTable. Table 2-1 lists commonly used methods of this class specific to the strongly typed DataSet.

Table 2-1. TableNameDataTable methods

Method

Description

AddTableNameRow( )

Adds a row to the table. The method has two overloads: one takes a TableNameRow object as the argument, while the other takes a set of arguments containing the column values.

FindByPrimaryKeyField1 ... PrimaryKeyFieldN( )

Takes N arguments which are the values of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required