clearly visual basic: programming with visual basic 2008 chapter 25 i’m suffering from information...
TRANSCRIPT
![Page 1: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/1.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
Chapter 25 I’m Suffering from Information
Overload
![Page 2: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/2.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
Objectives
• Define the terms used when talking about databases
• 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
2
![Page 3: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/3.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
Keeping Good Records
• 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
3
![Page 4: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/4.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
Keeping Good Records (continued)
• 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
![Page 5: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/5.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008 5
![Page 6: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/6.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
Keeping Good Records (continued)
• Figure 25-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
![Page 7: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/7.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008 7
![Page 8: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/8.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
Connecting … Connecting
• Figure 25-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– Easiest way to connect an application to a database
8
![Page 9: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/9.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008 9
![Page 10: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/10.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
Let the Computer Do It
• 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
![Page 11: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/11.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008 11
![Page 12: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/12.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
Let the Computer Do It (continued)
• 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
![Page 13: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/13.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
Let the Computer Do It (continued)
• 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 25-7
– Connects EmployeesDataSet to two bound controls• DataGridView control and BindingNavigator control
• Figure 25-8– Shows relationship between database, DataSet, and
Form
13
![Page 14: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/14.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008 14
![Page 15: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/15.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008 15
![Page 16: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/16.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
The Copy to Output Directory Property
• 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
![Page 17: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/17.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
How Does Visual Basic Do It?
• 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
17
![Page 18: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/18.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
Thank You for Catching My Errors
• 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
![Page 19: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/19.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008 19
![Page 20: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/20.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
I’ll Use My Own Controls, Thank You
• 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
• 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
20
![Page 21: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/21.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008 21
![Page 22: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/22.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008 22
![Page 23: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/23.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008 23
![Page 24: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/24.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
Summary
• Relational database 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
• You display the information contained in a dataset by: – Binding one or more of the dataset objects to one or
more controls in the application’s interface
24
![Page 25: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload](https://reader036.vdocuments.site/reader036/viewer/2022081520/5697c0191a28abf838ccea20/html5/thumbnails/25.jpg)
Clearly Visual Basic: Programming with Visual Basic 2008
Summary (continued)
• TableAdapter object – Connects a database to a DataSet object
• DataGridView control – Displays data in a row and columnar 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
25