DATA OVERVIEW

An application uses three basic objects to move data to and from a database: a connection, a data adapter, and a data container such as a DataSet.

The connection object defines the connection to the database. It contains information about the database’s name and location, any username and password needed to access the data, database engine information, and flags that determine the kinds of access the program will need.

The data adapter object defines a mapping from the database to the DataSet. It determines what data is selected from the database, and which database columns are mapped to which DataSet columns.

The DataSet object stores the data within the application. It can hold more than one table and can define and enforce relationships among the tables. For example, the database used in the earlier examples in this chapter has a TestScores table that has a StudentId field. The values in this field must be values listed in the Students table. This is called a foreign key constraint. The DataSet can represent this constraint and raise an error if the program tries to create a TestScores record with a StudentId value that does not appear in the Students table. The section “Constraints” later in this chapter says more about constraints.

When the connection, data adapter, and DataSet objects are initialized, the program can call the data adapter’s Fill method to copy data from the database into the DataSet. Later it can call the data adapter’s Update method to copy ...

Get Visual Basic 2012 Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.