Creating DataView Objects in Visual Studio .NET

Chapter 9

Working with Strongly Typed DataSet Objects

Over the past three chapters, you've learned how to create and use DataSet objects. The code used to access the contents of a DataSet is programmatically similar to code for accessing earlier objects such as the ADO and DAO Recordset objects, as you can see by comparing the following examples:

ADO.NET and Visual Basic .NET

txtCompanyName.Text = ds.Tables("Customers").Rows(0)("CompanyName")

ADO.NET and Visual C# .NET

txtCompanyName.Text = ds.Tables["Customers"].Rows[0]["CompanyName"];

ADO, DAO, and Visual Basic "Classic"

txtCompanyName.Text = rs.Fields("CompanyName").Value

Developers have been writing this kind of code since the early days of Visual Basic. Technically, there's nothing wrong with this code; it works. But that doesn't mean we can't improve on the old coding techniques.

To help you write data access code more easily, Microsoft Visual Studio .NET has introduced strongly typed DataSet objects. You can now write code that looks like this instead:

Visual Basic .NET

txtCompanyName.Text = ds.Customers(0).CompanyName

Visual C# .NET

txtCompanyName.Text = ds.Customers[0].CompanyName;

You can think of a strongly typed DataSet as a DataSet with class. More specifically, a strongly typed DataSet is a class that inherits from the DataSet class and also includes properties and methods based on the schema you specify. This class also contains other classes for your DataTable objects and DataRow objects. These are the classes that enable you to write data access code more efficiently.



Microsoft ADO. NET Core Reference
Microsoft ADO.NET (Core Reference) (PRO-Developer)
ISBN: 0735614237
EAN: 2147483647
Year: 2002
Pages: 104
Authors: David Sceppa

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net