A typed DataSet is a class that derives from a DataSet class and inherits all the methods , events, and properties of DataSet s. In other words, it looks and acts the same as a DataSet . A typed DataSet also provides strongly typed methods, events, and properties. All this translates to being able to access (in your code) the tables and columns by name , instead of using collection-based methods. In addition, Visual Studio .NET code editors use the typed DataSet to help automatically complete lines as you physically type a line of code. As previously stated, the strong typing of DataSet s also contributes to catching type mismatch errors at compile time as opposed to at runtime. In the next section, we will be generating the XML schema directly from some SQL Server tables and creating typed DataSet s for use in a coding example.
To generate a typed DataSet that can be used by many programs (and languages such as VB and C#), you must first start with an XML schema representation of the DataSet . This will be the .xsd XML file (XML Schema Definition). After this has been created, it can be turned into a typed DataSet and made available to programs that reference it properly (via a generated .dll). This .xsd schema of the DataSet must be compliant with the XML Schema definition language standards, available at http://www.w3.org/2001/XMLSchema and http://w3c.org.
After the XML Schema is generated, we will run it through the XSD.exe (XML Schema Definition) tool and create the typed class definitions in the appropriate language we would be using it with (such as VB or C#). We then compile the typed class definition as a library (.dll) to be used in our code. It's really that simple. All we then have to do is include the library (and Imports) in our VB code, and we can reference the strongly typed DataSet easily. Let's step through this process now. Later in this hour we will see how to do this using VS .NET Enterprise Architect as well.