ADO provides late bound access to values within its recordset through weakly typed variables. ADO+ provides the ability to access the data held in the DataSet through a "Strongly-Typed" metaphor. Meaning, you can access tables and columns that are part of the dataset through user-friendly names and strongly type variables. So, rather then doing :
A typed DataSet is a class that derives from DataSet. As such, it inherits all of the methods and properties of a DataSet. Additionally, however, a typed DataSet provides "strongly-typed" methods. In practice, this means you can access tables and columns by name, instead of using collection based methods. See also Section 1.2.3, "Programmability," in the introduction above.
For example, in ADO, you could use the following Visual Basic code to find a specific record in a recordset, and change the value of a field:
AdoRecordSet.Find("Customerid = 'ALFKI'") AdoRecordSet.Fields("FirstName").Value = "Bob"
In a typed DataSet, the same result would be obtained with this code:
CustomerDataSet.Customers("ALFKI").CustomerName = "Bob"
Aside the from the improved readability of the code, a typed DataSet also allows the compiler to automatically complete lines as you type.
Additionally, the "strongly-typed" DataSet provides access to row value as the correct strongly typed value. In case of ADO, you worked through variants when assigning and retrieving data. If the value that you assigned was of the wrong type, ADO would give you a run-time error. With ADO+, if the value is integer and you attempt to assign a string, you will get a compile-time error.
Given an XML schema that complies with the XSD standard, you can generate a "typed" dataset using the XSD.exe tool provided with this SDK. The syntax for generating a dataset using this tool is:
xsd.exe /d /l:C# {XSDSchemaFileName.xsd}
The /d directive tell the tool to generate a dataset and the /l: tells the tool what language to use. For the language you can use either "C#" or "VB."
The example below uses a typed dataset call "customerDataSet" to load a list of customer from the Northwind database. Once the data is loaded using the FillDataSet method, we loop through each customer in the "customers" table using the typed customerRow object. You will notice that we have direct access to the "customerid" field as opposed to accessing it through the fields collection.
[C#]
customerDataSet myCustDS = new customerDataSet(); SQLDataSetCommand myDSCommand = new SQLDataSetCommand("SELECT * FROM Customers", "server=localhost;uid=sa;pwd=;database=northwind"); myDSCommand.FillDataSet(myCustDS, "Customers"); foreach(customersRow myCustomer in myCustDS.customers) { Console.WriteLine(myCustomer.CustomerID.ToString()); }
[VB]
Dim myCustDS as DataSet = new dataset Dim myDSCommand as SQLDataSetCommand myDSCommand = new SQLDataSetCommand("Select * from customers", "server=localhost;uid=sa;pwd=;database=northwind") myDSCommand.FillDataSet(myCustDS, "Customers") Dim myCustomer as DataRow For Each myCustomer in myCustDS.Tables(0).Rows Console.WriteLine(myCustomer(0).ToString()) Next