In ADO 2.x we used one common set of classes to perform database connections, retrieve records, update data, execute stored procedures, etc. They were the ADO command, connection, error, field, parameter, property, record, recordset and stream classes.
In ADO.NET we have two sets of classes that we can use to access our data, depending on how that data is stored. Each of these classes is stored in a separate namespaces that clearly identifies them. To access data stored in an SQL Server database, we would use the classes that exist in the System.Data.SqlClient namespace. To access data stored in any other OLEDB accessible repository (such as Excel, MySQL, Access, and even SQL Server) we use the classes available under the System.Data.OleDb namespace.
[Note] If you're wondering why you can use both SQL and OleDb providers to access an SQL Server database, it's because the classes under the SqlClient namespace have been optimised to do so, where as the classed under the OleDb namespace are more generic, and therefore their performance isn't as good when working with SQL server. [End Note]
Here's a list of the namespaces that we use to access our data with ADO.NET:
- System.Data: The root class of the entire ADO.NET hierarchy, this namespace stores the generic data access classes and variables that are used by both the SqlClient and OleDb classes.
- System.Data.Common: Contains classes that data providers can use as base classes when implementing their own data access routines.
- System.Data.SqlClient: Contains the classes that we instantiate to access data stored in SQL Server databases.
- System.Data.SqlTypes: Data types including enumerations and constants that can be used when calling certain functions from the SqlClient namespace.
- System.Data.OleDb: Contains the classes that we instantiate to access data stored in OleDb compatible data repositories.
ADO.Net also defines several shared classes that are common to both the SqlClient and OleDb namespaces (i.e. can be used when we're working with either SQL server or any other OleDb provider). In ADO 2.x we used the recordset, command and stream classes to access data, but with ADO.NET we now have access to several new data access classes. These classes can be used to store, access, manipulate and relate data from one source to another. We will take a look at these later.
Let's now look at some examples of how we can access and manipulate our data using ASP/ADO and ASP.NET/ADO.NET. In the examples that follow I will be working with SQL server only.