- What Is a Database?
- Getting Data Out of Databases
- Kinds of Databases
- ODBC
- Database Structure
- Using ADO.NET
- Adding Rows to Database Tables Using ADO.NET
- Building the Façade Classes
- Making the ADO.NET Façade
- Creating Classes for Each Table
- Building the Price Table
- Loading the Database Tables
- The Final Application
Getting Data Out of Databases
Suppose we wanted to produce a table of employees and their salary ranges for some planning exercise. This table doesn't exist directly in the database, but it can be constructed by issuing a query to the database. We'd like to have a table that looked like the data in Table 18-2.
Table 18-2. Employee Salaries Sorted by Name
Name |
Min |
Max |
Adams |
$45,000.00 |
$60,000.00 |
Johnson |
$30,000.00 |
$45,000.00 |
Smyth |
$60,000.00 |
$75,000.00 |
Tully |
$30,000.00 |
$45,000.00 |
Wolff |
$45,000.00 |
$60,000.00 |
Maybe we want data sorted by increasing salary, as shown in Table 18-3. We find that the query we issue to obtain these tables has this form.
Table 18-3. Employee Salaries Sorted by Magnitude
Name |
Min |
Max |
Tully |
$30,000.00 |
$45,000.00 |
Johnson |
$30,000.00 |
$45,000.00 |
Wolff |
$45,000.00 |
$60,000.00 |
Adams |
$45,000.00 |
$60,000.00 |
Smyth |
$60,000.00 |
$75,000.00 |
SELECT DISTINCTROW Employees.Name, SalaryRanges.Min, SalaryRanges.Max FROM Employees INNER JOIN SalaryRanges ON Employees.SalaryKey = SalaryRanges.SalaryKey ORDER BY SalaryRanges.Min;
This language is called Structured Query Language or SQL (often pronounced "sequel"), and it is the language of virtually all databases currently available. There have been several standards issued for SQL over the years, and most PC databases support much of these ANSI standards. The SQL-92 standard is considered the floor standard, and there have been several updates since. However, not all databases support the later SQL versions perfectly, and most offer various kinds of SQL extensions to exploit various features unique to their database.