Introducing ADO.NET with ASP.NET 2.0
(Page 1 of 4 )
This is the first article in a series that I have written for anyone who wants to learn how to use ADO.NET technology, with an ASP.NET 2.0 page, to retrieve and update data. I assume that you have knowledge of C#, ASP.NET and Visual Studio.NET 2005.
In this article, we introduce the basics of ADO.NET. In subsequent articles we will talk more about how you can do advanced database operations from web pages. I will also show you code examples as I always present them in my articles.
ADO.NET is a set of classes that are organized in a number of namespaces. These namespaces provide developers access to databases to retrieve and update data. The classes of ADO.NET provide us with the means to access databases and execute T-SQL code that retrieves, inserts, updates and deletes data. It's critical to understand that ADO.NET depends on the concepts of data providers. ADO.NET doesn't have a general connection class that would access any database. ADO.NET has separated its functionality through the ADO.NET Data Providers.
A Data Provider is a set of classes that provide access to a specific data source for retrieving, updating and deleting operations between your application and the data source. Those classes are optimized to access and deal with that specific data source. This is the point of creating Data Providers and not using general classes to access any data source.
An ADO.NET Data Provider has the following classes:
Connection class: The connection class is used to connect to the data source. Note that different ADO.NET Data Providers have different connection classes. For example, the SQL Server Data Provider has the SqlConnection class, the Oracle Data Provider has the OracleConnection class and the OleDb Data Provider has the OleDbConnection class. So we don't have a class called connection because ADO.NET doesn't give us the ability to use general classes to access different data sources.
Command class: The command class is used to execute SQL statements on the data source. As you might have guessed there is nothing called a command class in ADO.NET and different ADO.NET Data Providers have different command classes. The SQL Server Data Provider has a SqlCommand class and the same applies to the other Data Providers; each one has its own command class.
Data reader class: This class provides access to a database table in a read-only forward-only behavior. The SQL Server Data Provider has the SqlDataReader class; other Data Providers also have their own implementations of the data reader. For example, the OleDbDataReader is the class for the OleDb Data Provider and so on.
Data adapter class: The data adapter class submits changes made to the data in your application. This data is in the form of a DataSet object to the data source. The SQL Server Data Provider has the SqlDataAdapter class; other Data Providers also have their own implementations of the data adapter. For example, the OleDbDataAdapter is the class for the OleDb Data Provider and so on.
ADO.NET is shipped with four Data Providers, but you can create your own provider if you need to access another data source that has no Data Provider. The four Data Providers are as follows:
- The SQL Server Data Provider is used, and optimized, to access SQL Server 2005, 2000 and version 7.0 databases. Its classes lives in the System.Data.SqlClient namespace.
- The Oracle Data Provider is used to access Oracle databases and its classes lives in the System.Data.OracleClient namespace.
- The OLE DB Data Provider is used to access any data source that has an OLE DB Driver. Its classes lives in the System.Data.OleDb namespace.
- The ODBC Data Provider is used to access any data source that has an ODBC Driver. Its classes lives in the System.Data.Odbs namespace.
Throughout the series I will be using the SQL Server Data Provider because I'm using SQL Server as the database server for all of my code examples. In one of the next articles I will show you how you can write generic data access code that you can use to access any data source as long as it has an ADO.NET Data Provider. So enough theory and let's get to the code examples.
Next: Populating a ListBox control from the Northwind database >>
More ASP.NET Articles
More By Michael Youssef