Professional Visual Studio 2005 (2006) [eng]
.pdf
Strongly Typed DataSets
A large proportion of applications use some form of data storage. This might be in the form of serialized objects or XML data, but for long-term storage that supports concurrent access by a large number of users, most applications use a database. The .NET Framework includes strong support for working with databases and other data sources. This chapter examines how to use strongly typed DataSets to build applications that work with data from a database.
This examples in this chapter are based on the sample AdventureWorks database that is available as a download from www.microsoft.com.
DataSet Over view
The .NET Framework DataSet is a complex object that is approximately equivalent to an in-memory representation of a database. It contains DataTables that correlate to database tables. These in turn contain a series of Columns that define the composition of each DataRow. The DataRow correlates to a row in a database table. Of course, it is possible to establish relationships between DataTables within the DataSet in the same way that a database has relationships between tables.
One of the ongoing challenges for the object-oriented programming paradigm is that it does not align smoothly with the relational database model. The DataSet object goes a long way toward bridging this gap, as it can be used to represent and work with relational data in an object-oriented fashion. However, the biggest issue with a raw DataSet is that it is weakly typed. Although the type of each column can be queried prior to accessing data elements, this adds overhead and can make code very unreadable. Strongly typed DataSets combine the advantages of a DataSet with strong typing to ensure that data is accessed correctly at design time. This is done with the custom
