Creating Typed DataSets For More Efficient Programming
This article aims to give you an introduction to the technique of creating rich and powerful DataSets with the help of C# to make your programming efforts more efficient and precise. At the same time, you can provide type safety for DataSets by using Typed DataSets, to avoid errors at runtime.
Tools and Technologies Used
We will be using the following tools and technologies to build our example:
SQL Server 2000
This article assumes that you are already familiar with the concepts of ADO.NET DataSet.
Typed DataSets are not a set of .NET Framework classes like DataSets are. They are the classes generated by tools provided with .NET Framework, and they have complete DataSet functionality (methods, events, and properties) with some additional benefits.
Clearly, to have all the functionality of DataSets, Typed DataSets directly inherit from the DataSet classes. Some additional code generated by .NET Framework tools gives all the additional benefits of Typed DataSets. Furthermore, you can access table and columns by name instead of having to use collection-based methods with DataSets and using indexers until you reach the DataRow level. That involves a greater possibility that a table or column name will be misspelled, resulting in an error at runtime.
Aside from the improved readability of the code, a typed DataSet allows the Visual Studio.NET code editor to automatically complete lines while typing (using Intellisense functionality). Typed DataSets also provide access to values of the correct type at compile time. Thus, mismatch errors are reported at compile time and are not delayed to runtime. This is known as type-safe access to the DataSethence the name Typed DataSets.