Open the Paradise.exe file Application displays records in the Books database Allows the store manager to enter an author’s name (or part of a name) Displays only books written by the author Displays the total value of books in the store 2
3 Figure 13-1 Books written by Carol Smith
After studying Lesson A, you should be able to: Define basic database terminology Connect an application to a Microsoft Access database Bind table and field objects to controls Explain the purpose of the DataSet, BindingSource, TableAdapter, TableAdapterManager, and BindingNavigator objects Customize a DataGridView control Handle errors using the Try…Catch statement Position the record pointer in a dataset 4
Computer database Electronic file containing an organized collection of related information Relational database Database that stores information in tables composed of rows and columns Each column in a table represents a field Each row in a table represents a record Field Single piece of information about a person, place, or thing 5
Record Group of related fields that contain all the necessary data about a specific person, place, or thing Table: Group of related records Each record in a table pertains to the same topic and contains the same type of information Primary key: Field uniquely identifying a record A two-table database has parent and child tables Foreign key Field that links a child record to a parent record 6
7 Figure 13-3 Example of a one-table relational database
8 Figure 13-4 Example of a two-table relational database
Advantages of a relational database Data can be retrieved quickly and easily Data can be displayed in any order You can control how much data to view 9
Must bind one or more objects in the dataset to controls in the interface to view dataset contents Binding Connecting an object to a control Bound controls Connected controls Types of controls used to bind dataset objects Computer-created control Existing control on the form 10
11 Figure Ways to bind an object in a dataset
12 Figure Result of dragging the table object to the form
In addition to a control, the computer adds: BindingNavigator control: To move from one record to the next in the dataset TableAdapter object: Connects the database to the DataSet object; responsible for retrieving data and storing it in the DataSet TableAdapterManager object: Handles saving data to multiple tables in the DataSet BindingSource object: Provides the connection between the DataSet and the bound controls 13
14 Figure Illustration of the relationships among the database, the objects in the component tray, and the bound controls
DataGridView control Displays data in a row and column format Cell: Intersection of a row and column DataGridView’s task list allows you to add, reorder, and remove columns and set properties of bound columns AutoSizeColumnsMode: Has seven settings that control how the column widths are sized Fill setting: Automatically adjusts the column widths so that the display area of the control is filled 15
16 Figure DataGridView control’s task list
17 Figure Purpose of each task in the DataGridView’s task list
18 Figure Edit Columns dialog box
19 Figure Completed CellStyle Builder dialog box
20 Figure DataGridView control after setting some of its properties
Open the Morgan Industries Solution (Morgan Industries Solution.sln) file contained in the VB2010\Chap13\Morgan Industries Solution-Labels folder 21
ทำการเชื่อมต่อฐานข้อมูลด้วย Data Source Configuration Wizard 22
23
24
After studying Lesson B, you should be able to: Query a dataset using LINQ Customize a BindingNavigator control Use the LINQ aggregate operators 25
You use a query to specify both the records to select in a dataset and the order in which to arrange the records. You can create a query in Visual Basic using a language feature called Language Integrated Query ( LINQ) 26
27
28
29
30
31
32
33
After studying Lesson C, you should be able to: Prevent the user from adding and deleting records Remove buttons from a BindingNavigator control Add a label, a text box, and a button to a BindingNavigator control 34
35