19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

350 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

SUMMARY<br />

1. A table is a group of data items arranged in a rectangular array, each containing<br />

the same categories of information. Each data item (row) is called a record.<br />

Each category (column) is called a field. Two tables with a common field are<br />

said to be related. A database is a collection of one or more, usually related,<br />

tables.<br />

2. The data control is used to access a database. When a text box is bound to a<br />

data control through its DataSource <strong>and</strong> DataField properties, the user can read<br />

<strong>and</strong> edit a field of the database. At any time, one record is specified as the<br />

current record. The user can change the current record with the data control’s<br />

navigator arrows or with Move statements. The property RecordCount count<br />

records, the property BOF indicates whether the beginning of the recordset has<br />

been reached, <strong>and</strong> the property EOF indicates whether the end of the recordset<br />

has been reached. The Value property of Fields (“fieldName”) reads the contents<br />

of a field of the current record. The Validate event, which can be used to<br />

control edits, is triggered whenever the current record is about to be changed.<br />

3. A primary key is a field or set of fields that uniquely identifies each row of a<br />

table. The rule of entity integrity states that no record can have a null entry in a<br />

primary key. A foreign key is a field or set of fields in one table that refers to a<br />

primary key in another table. The rule of referential integrity states that each<br />

value in the foreign key must also appear in the primary key.<br />

4. Structured Query Language (SQL) is used to create a “virtual” table consisting<br />

of a subtable of a table or of a join of two tables <strong>and</strong> imposes an order on the<br />

records. The subtable is specified with the reserved words SELECT, FROM,<br />

WHERE, ORDER BY, <strong>and</strong> INNER JOIN . . . ON. The WHERE clause of an<br />

SQL statement commonly uses the Like operator in addition to the st<strong>and</strong>ard<br />

operators. SQL statements are either employed at design time or run time as the<br />

setting of the RecordSource property. During run time, the Refresh method for<br />

the data control should be executed after the RecordSource property is set.<br />

5. The MS FlexGrid grid control can show an entire “virtual” table in a spreadsheet-like<br />

display. Data-bound list box <strong>and</strong> data-bound combo box controls can<br />

display the contents of a single field for an entire table or recordset.<br />

6. <strong>Visual</strong> Data Manager, a database management program supplied with most versions<br />

of <strong>Visual</strong> <strong>Basic</strong>, can be used to create a database <strong>and</strong> specify primary keys<br />

<strong>and</strong> validation criteria. A database can be created by code with the Professional<br />

or Enterprise editions of <strong>Visual</strong> <strong>Basic</strong>.<br />

7. Although good database design is an art, there are several fundamental principles<br />

that usually should be followed.<br />

PROGRAMMING PROJECTS<br />

1. The database MICROLND.MDB (on the accompanying CD) is maintained by<br />

the Microl<strong>and</strong> <strong>Computer</strong> Warehouse, a mail order computer supply company.<br />

Tables 11.7 through 11.9 show parts of three tables in the database. The table<br />

Customers identifies each customer by an ID number <strong>and</strong> gives, in addition to<br />

the name <strong>and</strong> address, the total amount of purchases during the current year.<br />

The table Inventory identifies each product in stock by an ID number <strong>and</strong> gives,<br />

in addition to its description <strong>and</strong> price (per unit), the quantity currently in stock.<br />

The table Orders gives the orders received today. Suppose it is now the end of<br />

the day. Write a program that uses the three tables to do the following:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!