You briefly looked at the ADO.NET architecture in Chapter 1. Now you'll see a broad view of the ADO.NET architecture and learn how disconnected and connected components (classes) provide access to multiple data sources. In this section, we talk about objects in general.
Figure 3-1 shows the basic architecture of the ADO.NET model. As you can see, the entire ADO.NET model sits between the data source and client applications that can be built using Windows Forms, Web Forms, or even console-based applications. The Connection is the first component that talks to a data source. In ADO.NET, each data provider (OleDb, Sql, Odbc, or Oracle) has its own Connection class. The Connection component is a mediator between a DataAdapter or a Command component. The DataAdapter components create SQL INSERT, SELECT, UPDATE, and DELETE statements that add, read, update, and delete data from a data source, respectively. Not only does a DataAdapter create these SQL statements, it also executes these statements. Basically, a DataAdapter (with the help of Command) physically updates and reads data from a data source. In Figure 3-1, an arrow shows this flow of data.
Figure 3-1: ADO.NET architecture
You can use the Command components with or without a DataAdapter. You can directly execute commands and read data in a DataReader, which provides a read-only, forward-only fast access to data. This is best when you need to read data in applications that are not data-bound. You can also see from Figure 3-1 that all arrows are double-sided arrows except the arrow connecting a DataReader and Command. A double-sided arrow means data transfer is possible on both sides. A DataReader can only read data, which is why the DataReader has only a one-sided arrow. This shows that you can fill a DataReader from the Command, but you can't send back data from a DataReader to the Command.
A DataAdapter sits between a data source and a DataSet. It provides Fill and Update methods to fill a DataSet from a data source based on the SELECT statement, and the Update method saves a DataSet's changes to the data source. The DataSet plays a vital role in data-bound Graphical User Interface (GUI) applications to display and manipulate data. Not only does it provide fast data manipulation using Extensible Markup Language (XML) schemas, it also provides multiple views of data that can be bound with multiple Windows Forms and Web Forms data-bound controls.
A DataSet is a collection of DataTable components. A DataTable represents a table in a data source. You can apply a filter or do sorts on a table. You can bind a DataTable to data-bound controls such as a DataGrid, DataList, ListBox, or ComboBox using DataView. You can also apply sorts and filters on a DataView. As you can see from Figure 3-1, there are three DataSets represented and three DataTables. Each DataTable binds to different data-bound controls using different DataViews.
This section gave you an overview of the ADO.NET architecture. We discuss these controls in more detail throughout this chapter and Chapter 4, depending on their category.