Adding Typed DataSets in ADO.NET

This article has been excerpted from the book "A Programmer's Guide to ADO.NET in C#".
 
In the previous article, your way saw how you can generate DataSet objects from a data adapter. There are other ways to create a typed DataSet object.
 
You can click on the project menu and choose Add New Item (or click Ctrl +D). This brings up the Add New Item window where you'll find the Data Set template (see figure 4-50).
 
Figure-4.50.gif
 
Figure 4-50. Creating a typed Dataset from the Add New Item window
 
After adding the DataSet, the designer creates an XSD (XML schema) file and adds it to your project area. As you can see from figure 4-51, myDS.xsd is empty.
 
Figure-4.51.gif
 
Figure 4-51. myDS.xsd in VS.NET
 
Next, drop a table (or multiple tables) from the Server Explorer to the form (see figure 4-52).
 
Figure-4.52.gif
 
Figure 4-52. Drag and drop tables from the Server Explorer to the from to create a typed Dataset
 
This action adds one XML schema (MyDS.xsd), which looks like figure 4-53.
 
Figure-4.53.gif
 
Figure 4-53. Design View of the XML schema of the Dataset
 
It also automatically adds the typed DataSet class that inherits from DataSet. As you can see in figure 4-54, the myDS class contains members used to access data from the database.
 
Figure-4.54.gif
 
Figure 4-54. Wrapper class generated for the typed DataSet
 
Once you have this class, you can create an instance of this class and work with its property fields directly:
  1. MyDSet ds = new MyDSet(); 

Conclusion

 
Hope this article would have helped you in understanding Adding Typed DataSets in ADO.NET. See my other articles on the website on ADO.NET.
 
adobook.jpg
 
This essential guide to Microsoft's ADO.NET overviews C# then leads you toward a deeper understanding of ADO.NET.



Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.