Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tutorial 91 Databases A database is an organized collection of related information stored in a file on a disk A database allows companies to store information.

Similar presentations


Presentation on theme: "Tutorial 91 Databases A database is an organized collection of related information stored in a file on a disk A database allows companies to store information."— Presentation transcript:

1

2 Tutorial 91 Databases A database is an organized collection of related information stored in a file on a disk A database allows companies to store information about employees, customers, inventory, and so on

3 Tutorial 92 Visual Basic and Databases You can use Visual Basic to access databases created by many popular software packages Visual Basic allows a company to use one interface to access all of a company’s data You can use Visual Basic to create a Microsoft Access database because both Visual Basic and Microsoft Access contain the Jet engine

4 Tutorial 93 Relational Databases A relational database stores data in tables, which are composed of columns and rows Each column in the table represents a field and each row in the table represents a record

5 Tutorial 94 Field, Record, Table, Relational Database Field – single item of information about a person, place, or thing Record – group of related fields that contain all of the information about a person, place, or thing Table – group of related records; each record contains the same fields Relational database – one or more tables

6 Tutorial 95 One-table Relational Database

7 Tutorial 96 Two-table Relational Database The records are related by the CD number

8 Tutorial 97 Advantages of Relational Databases Provide easy and quick retrieval of information Allow you to display the data in any order Allow you to control how much of the data (which fields and records) are displayed at any one time

9 Tutorial 98 Five Design Steps Identify the information the user will need from the database Organize the information into one or more tables Establish relationships between tables (if the database contains more than one table) Create one or more indexes, if necessary Define data validation rules, if necessary

10 Tutorial 99 Index A special table that is created and maintained by Visual Basic Allows you to arrange the records in a specific order, and also quickly search for information Create an index only for fields on which you plan either to order or to search

11 Tutorial 910 Index For each record, the index stores two fields Index field – stores values contained in the field being indexed Pointer field – stores a number that represents (points to) the location of the record in the table

12 Tutorial 911 Index and Pointer Fields

13 Tutorial 912 Data Validation Data validation refers to the process of ensuring that the data in the database meets certain criteria A data validation rule places restrictions on the data entered in a field

14 Tutorial 913 Summary Chart Table name:tblPatron Field names:fldSeat, fldName, fldPhone Relationships:None Index: Create an index named indSeat for the fldSeat field Validation rule: The fldSeat field must contain a number that is greater than or equal to 1 and less than or equal to 48

15 Tutorial 914 Visual Data Manager Application that comes with Visual Basic Use to create a Microsoft Access database, including indexes and data validation rules Click Add-Ins on the Visual Basic menu bar, then click Visual Data Manager, and then open a new or existing Microsoft Access 7.0 database

16 Tutorial 915 Visual Data Manager

17 Tutorial 916 Table Structure Dialog Box

18 Tutorial 917 Add Field Dialog Box

19 Tutorial 918 Fields Shown in the Database Window

20 Tutorial 919 Add Index Dialog Box

21 Tutorial 920 Validation Rules

22 Tutorial 921 Dynaset Window

23 Tutorial 922 Find Record Dialog Box

24 Tutorial 923 Like Operator and * Wildcard

25 Tutorial 924 UDA, OLE DB, ADO UDA – Microsoft’s approach to solving the data access problem OLE DB – provides uniform access to data stored in a variety of formats; Visual Basic programmers gain access to the complex OLE DB interfaces through ADO ADO – allows you to access the OLE DB interfaces

26 Tutorial 925 ADO Data Control Microsoft’s ADO (ActiveX Data Object) data control can access the data stored in a variety of formats, such as a database, a spreadsheet, or even a text file The ADO data control establishes a link between the database and the other controls in the application’s interface

27 Tutorial 926 ADO Data Control

28 Tutorial 927 Provider Tab

29 Tutorial 928 Connection Tab

30 Tutorial 929 General Tab

31 Tutorial 930 RecordSource Tab

32 Tutorial 931 Binding Controls Connecting a control to an ADO data control is called binding, and the connected controls are referred to as data-aware controls or bound controls Any control that has a DataSource property can be bound to an ADO data control

33 Tutorial 932 Binding Controls Set the control’s DataSource property to the name of the ADO data control Set the control’s DataField property to the name of a field in the database Always set the DataSource property before setting the DataField property

34 Tutorial 933 SQL Stands for Structured Query Language A set of commands that allow you to access and manipulate the data stored in many database management systems on computers of all sizes SQL commands can be used to store, retrieve, update, and sequence data

35 Tutorial 934 SQL Select Statement select fields from table [where condition] [order by field] Fields is one or more field names, separated by commas Table is the name of the table containing the fields Where condition clause allows you to limit the records that appear when displayed Order by field clause allows you to control the order in which the records appear when displayed

36 Tutorial 935 Select Command Example

37 Tutorial 936 Select Command Example

38 Tutorial 937 Where Clause Examples To view seat 24’s record, select * from tblPatron where fldSeat = 24 To view all records, in seat number order, whose seat numbers are greater than 20, select * from tblPatron where fldSeat > 20 order by fldSeat To view Candy Sprott’s record, select * from tblPatron where fldName = “sprott, candy” To view all records whose phone number begins with 333, select * from tblPatron where fldPhone like “333%”

39 Tutorial 938 RecordSet and Field Objects and the Fields Collection Recordset object - the collection of records selected by the ADO data control’s RecordSource property Each field contained within the Recordset object is referred to as a Field object The collection of Field objects within a Recordset object makes up the Fields collection To refer to a field within the Fields collection: [form.]adocontrol.Recordset.Fields(field)

40 Tutorial 939 Recordset and Field Objects and the Fields Collection The select * from tblPatron command will create the following Recordset object, Field objects, and Fields collection: Recordset object: All records stored in the tblPatron table Fields collection: fldSeat, fldName, fldPhone 3 Field objects

41 Tutorial 940 Methods of the Recordset Object AddNewAdd a new, blank record to the end of the recordset CancelUpdateCancel changes made to the current record DeleteDelete the current record from the recordset MoveFirstMove the record pointer to the first record in the recordset MoveNextMove the record pointer to the next record in the recordset UpdateSave the changes made to the current record

42 Tutorial 941 Recordset Object’s EOF Property EOFTest for the end of the recordset The EOF property contains True if the record pointer is positioned after the last record in the recordset; otherwise, the property contains False

43 Tutorial 942 Syntax of Recordset Object’s Methods and Properties The syntax for invoking a method of the Recordset object is: [form.]adocontrol.Recordset.method The syntax for referring to a property of the Recordset object is: [form.]adocontrol.Recordset.property.

44 Tutorial 943 ADO Data Control’s Refresh Method adocontrol.Refresh To create a new Recordset object while an application is running, you need first to enter, into a code window, an instruction that resets the ADO data control’s RecordSource property. You then need to use the ADO data control’s Refresh method to reopen the database and recreate the Recordset object

45 Tutorial 944 Visible vs Enabled If the application never allows the user to interact with the ADO data control, then you should hide the control If the application allows the user to interact with the ADO data control when a certain condition is met, then you should disable the control and enable it when the condition is met

46 Tutorial 945 Debugging Technique The Debug menu’s Step Into command allows you to execute the application’s code one statement at a time You also can use the Step Into button on the Debug toolbar to access the Step Into command; or you can press the F8 key on your keyboard


Download ppt "Tutorial 91 Databases A database is an organized collection of related information stored in a file on a disk A database allows companies to store information."

Similar presentations


Ads by Google