Visual Basic .NET uses what is called the ADO.NET model for accessing databases. Prior versions of Visual Basic used ADO (ActiveX Data Objects), DAO (Data Access Objects), and RDO (Remote Data Objects) for accessing databases. Each of these database access methodologies had its limitations. Perhaps the most serious limitation was that the technologies were Windows-specific. If the database couldn't be run on a Windows platform, you couldn't talk to it. Further, the underlying format of the data was specific to ADO and exchanging database information was restricted, especially with respect to Internet communications. Also, ADO was not terribly efficient and had the appearance of being an OOP afterthought that was slapped together at the last moment.
ADO.NET removes most of the major drawbacks of earlier versions. Also, it's easy to use XML (discussed in a later chapter) in the ADO.NET model to make data exchanges much simpler.
Before we can obtain any information from a database, we must perform several steps. Those steps are illustrated in Figure 24.3.
Figure 24.3. ADO.NET steps for accessing a database.
The Connection object serves as a starting point in accessing a database. The purpose of the Connection object is to provide the details about the database that are necessary to make a connection with the database. Although a number of parameters are passed as part of the connection string, the most important are Provider and Data Source parameters. The Provider parameter tells Visual Basic .NET the type of database that we're accessing, and the Data Source parameter provides the full pathname of the database. (I provide examples of these in Chapter 25, "Database Programming with Visual Basic .NET.") As you can see in Figure 24.3, the Connection object becomes our physical connection to the database.
The second step we must perform is to create a Data Adapter object. The Data Adapter object enables us to manage the data associated with the database. The Data Adapter object not only enables us to retrieve data from the table, but also manages any changes we might want to make to the database (for example, adding, deleting, or editing a record).
From the Data Adapter, we can create datasets that are representations of the data we requested from the database. The datasets are held in memory and are therefore temporary. The datasets contain not only the record information we request, they also contain information about the table itself, such as the column names , the type of data stored in a specific field, and other details that might prove useful in manipulating the data. Dataset data is stored in XML documents, which is one reason data exchanges via the Internet are so much easier in Visual Basic .NET than in previous version of Visual Basic. However, we can use the data as though it is stored in native Visual Basic .NET data types.
We don't need to concern ourselves with the XML format at this moment, however, because the objects we'll use to display the information know how to format the XML data for us. Therefore, when we move data between the dataset and a Visual Basic .NET form, Visual Basic .NET takes care of all the data conversion and formatting issues for us.