Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 24 I’m Suffering from Information Overload (Access Databases) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition.

Similar presentations


Presentation on theme: "Chapter 24 I’m Suffering from Information Overload (Access Databases) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition."— Presentation transcript:

1 Chapter 24 I’m Suffering from Information Overload (Access Databases) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition

2 Objectives Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 2 After studying Chapter 24, you should be able to: Define basic database terminology Connect an application to a Microsoft Access database Bind table and field objects to controls Customize a DataGridView control Handle exceptions using the Try…Catch statement Position the record pointer in a dataset

3 Keeping Good Records Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 3 Computer database Electronic file that contains an organized collection of related information Relational database Stores information in tables composed of columns and rows Field Single item of information about a person, place, or thing

4 Keeping Good Records (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 4 Record Group of related fields that contain all the necessary data about a specific person, place, or thing Table Group of related records Primary key Field that uniquely identifies each record in a table 4

5 Keeping Good Records (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 5 5 Figure 24-1 Example of a one-table relational database

6 Keeping Good Records (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 6 Figure 24-2 CD_Number field Primary key in parent table CD_Number field in child table Used solely to link song title and track information to the appropriate CD in parent table Child table CD_Number field is called the foreign key 6

7 Keeping Good Records (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 7 7 Figure 24-2 Example of a two-table relational database

8 Connecting …Connecting Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 8 Figure 24-3 Emp_Number field is the primary key Status field contains the employment status Code field identifies the employee’s department Data Source Configuration Wizard Easy way to connect an application to a database 8

9 Connecting …Connecting (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 9 9 Figure 24-3 Data contained in the tblEmploy table

10 Let the Computer Do It Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 10 Binding Connecting an object to a control Bound controls The connected controls DataGridView control Displays data in row and columnar format, similar to a spreadsheet One of the most popular controls for displaying table data 10

11 Let the Computer Do It (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 11 Figure 24-7 DataGridView control’s task list

12 Let the Computer Do It (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 12 While an application is running, you can use the BindingNavigator control to: Move from one record to the next in the dataset Add or delete a record and save any changes made to the dataset Component tray Stores objects that do not appear in the user interface while an application is running TableAdapter object in the component tray Connects the database to the DataSet object 12

13 Let the Computer Do It (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 13 TableAdapterManager object Used to save changes made to the database BindingSource object Provides the connection between the DataSet and the bound controls on the Form TblEmployBindingSource in Figure 24-8: Connects EmployeesDataSet to two bound controls DataGridView control and BindingNavigator control Figure 24-9 Illustrates relationships 13

14 Let the Computer Do It (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 14 Figure 24-8 Result of dragging the tblEmploy object to the form

15 Let the Computer Do It (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 15 Figure 24-9 Illustration of the relationships among the database, the objects in the component tray, and the bound controls

16 The Copy to Output Directory Property Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 16 When the Data Source Configuration Wizard connects an application to a database: It adds the database file to the application’s project folder Method of saving changes to a local database file Is determined by the file’s Copy to Output Directory property 16

17 How Does Visual Basic Do It? Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 17 When a table or field object is dragged to the form: Computer adds the appropriate controls and objects to the application A form’s Load event Occurs when the application is started and the form is displayed for the first time Load event procedure Code to fill a dataset with data belongs here in most applications 17

18 Thank You for Catching My Errors Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 18 Exceptions Handled in Visual Basic by displaying an error message and then abruptly terminating the application Try…Catch statement Used to take control of the exception handling in your code 18

19 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 19 Figure 24-15 Syntax and examples of the Try…Catch statement (continues)

20 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 20 Figure 24-15 Syntax and examples of the Try…Catch statement (cont’d.)

21 I’ll Use My Own Controls, Thank You Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 21 To bind an object in a dataset to an existing control on the form: Drag the object from the Data Sources window to the control Or click the control Then set one or more properties in the Properties window Appropriate property to set depends on the control you are binding 21

22 Coding the Next Record and Previous Record Buttons Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 22 BindingSource object Uses an invisible record pointer to keep track of the current record in the dataset Position property Stores the position of the record pointer Move methods Can be used to position the record pointer in a dataset Moves the pointer to the first, last, next, or previous record 22

23 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 23 Figure 24-19 Syntax and examples of the BindingSource object’s Position property

24 Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 24 Figure 24-20 Syntax and examples of the BindingSource object’s Move methods

25 Summary Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 25 Relational databases can contain one or more tables Data in a relational database Can be displayed in any order Most tables contain a primary key that uniquely identifies each record To access the data stored in a database: First connect the application to the database

26 Summary (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 26 TableAdapter object Connects a database to a DataSet object DataGridView control Displays data in row and column format Try…Catch statement Used to handle exceptions that occur while an application is running BindingSource object Uses an invisible record pointer to keep track of the current record in a dataset 26


Download ppt "Chapter 24 I’m Suffering from Information Overload (Access Databases) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition."

Similar presentations


Ads by Google