Download VB Database Connectivity - West Virginia University

Document related concepts

Open Database Connectivity wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Concurrency control wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Database wikipedia , lookup

Relational model wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Functional Database Model wikipedia , lookup

Clusterpoint wikipedia , lookup

Database model wikipedia , lookup

Transcript
Web-Enabled Decision Support Systems
Database Connectivity with ADO .NET
Don McLaughlin
West Virginia University
[email protected]
(304) 293-0405x4258
1
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
2
Introduction

A database application is a computer program that allow users to
manipulate data in a DBMS through a user-friendly interface

Examples:
– Amazon.com
 Online shopping
– Mapquest.com
 Driving directions
– University portals
 Transcripts and tuition payment information
3
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
4
Database Application Types

We classify database applications into the following three categories:
– Display-oriented applications


Display data retrieved from a relational database on forms or web pages
Examples: Online newspapers, portal to view student transcript and grades,
mapping websites
– Transaction-oriented applications


Involve frequent transfer of data to and from a database
Examples: Online shopping, portal for university faculty to enter student grades
– Communication-oriented applications


Communicate with other applications or processes
Examples: Application with underlying optimization software, Crystal Reports,
Map Point
5
Database Application Overview

A VB .NET database application involves connectivity between a
database and a graphical user interface (GUI)

Achieved through ActiveX Data Objects (ADO) .NET
– A collection of objects (classes) designed to support data access and
manipulation
– The ADO .NET architecture forms the basis of VB .NET database
applications
– ADO .NET object examples:
 Connection object
 TableAdapter object
 DataSet object
6
Database Application Processes
1.
Connecting to the database
– Establish a two-way communication channel via Connection object
2.
Fetching data using database queries
– Bring data into an application in the desired format (filtered, sorted, etc.) via
TableAdapter object
3.
Temporarily storing the result somewhere
– Via DataSet object
4.
Displaying data on Windows forms
– Data binding
5.
Editing data in the application
6.
Saving updated data back in the database
7
Database Application Data Cycle
Database Application Data Cycle
8
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
9
Create the Project

How-to: Create a Simple Database Application
1. In Visual Studio, choose the File | New Project option from the Main menu to
open the New Project dialog box.
2. Make sure to select the Windows Application icon in the Templates area.
3. Name the project DatabaseConnectivity and click OK.
10
Create a Data Source
4. Choose the Data | Show Data Sources option from the Main menu.
Opening the
Data Sources Window
5. In the Data Sources Window, click Add New Data Source to start the Data
Source Configuration Wizard.
Invoking the Data Sources
Configuration Wizard
11
Create a Data Source (cont.)
6. Select the Database icon on the Choose a Data Source Type page of the
wizard. Click Next.
Choosing a
Data Source Type
12
Create a Data Source (cont.)
7. On the Choose Your Data Connection page, click New Connection to open
the Choose Data Source dialog box.
Specifying the Data Connection
13
Create a Data Source (cont.)
8. Select the Microsoft Access Database File in the Data Source list box. Click
on Continue.
9. In the Add Connection dialog box that opens, select the University database
file. Click Test Connection to verify the connection. Click OK.
Creating the
Database Connection
14
Create a Data Source (cont.)
10. Click Yes to copy the database to the current project folder. Click Next.
11. On the Save the Connection String to the Application Configuration File
page, save the connection string with its default name. Click Next.
Saving the Connection String
15
Create a Data Source (cont.)
12. Expand the Tables node on the Choose your Database Objects page, and
select the student, department, transcript, and faculty tables. Click Finish.
Selecting Database Tables for a Data Source
16
Using a DataGridView Control
13. In the Data Sources Window, drag the student table onto Form1 to create
the DataGridView control along with a ToolStrip at the top of the form.

The ToolStrip provides controls for navigation, adding/deleting records, and
saving data
Drag-and-Drop to Create
DataGridView Control
Snapshot of the
Component Tray
17
Test the Application
14. Press Ctrl + F5 to run the application.
15. Test the ToolStrip functionality by navigating through the student records.
16. Alter values in the DataGridView control, and click on the Save button in the
ToolStrip to modify the data.
Application
Output
18
Property Window Review
17. Click the smart tag on the DataGridView control to view its Tasks list.


Note that the DataSource property is set to the TblStudentBindingSource.
Also note the automatic enabling of various options.
Tasks List of a DataGridView Control
19
Code Review
18. Double click anywhere on the form to open the code behind window.

Review the auto-generated code that was created when we dragged the student
table from the Data Sources Window.
Form1_Load Event Populating the Student DataTable
20
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
21
Auto-Created Objects in the Component Tray

Four objects were added to the Component tray when we dragged the
student table node from the Data Sources Window onto Form1:
1. TableAdapter object


Host for SQL queries
Corresponding to each query, has a Fill method that executes a SQL query
2. DataSet object



Acts as an in-memory data repository
Can have any number of DataTables
DataTables are populated using a TableAdapter, by means of results of SQL
queries
22
Auto-Created Objects in the Component Tray (cont.)
3. BindingSource object

Mediator between a Windows control and a DataSet
BindingSource Object Work Diagram
4. BindingNavigator object

Enables users to navigate through and manipulate data on Windows forms with
the help of a ToolStrip control
23
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
24
Setting the Controls to be Created

How-to: Display Data in Individual Windows Controls
1. Add a new form, Form2, to the DatabaseConnectivity application.
2. In the Data Sources Window, select the student table node, and click the
drop-down arrow to select the Details option. The default is the
DataGridView control.
Selecting the Details Option
for a Table Display
25
Setting the Controls to be Created (cont.)
3. Expand the tblStudent node in the Data Sources Window.
4. Choose the controls for all the columns as shown below.
Individual Displaying
Controls for the Columns
of the Student Table
26
Setting the Controls to be Created (cont.)
5. Drag the tblStudent node from the Data Sources Window onto Form2 to
create individual data-bind controls for each selected column.

These controls are accompanied by appropriately titled Label controls.
Individual Controls
Shown in Form’s
Design View
27
Test the Application
6. Set Form2 as the start-up form. Press Ctrl + F5 to run the application. The
first record displayed is shown below.
7. Use the ToolStrip on top of the form to navigate through the records. Edit the
value of any field, and click Save to test its functionality.
Student Table
Displayed One
Record at a Time
28
Property Window Review
8. Select the TextBox control for the Name field, and navigate to its
DataBindings property in the Property Window.

Note that the Text property of the Name TextBox is associated with the Name
column from the TblStudentBindingSource.
Data Binding Properties
for the Name Column’s
TextBox Control
29
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
30
Adding a PictureBox Control

How-to: Bind Data to Existing Controls
1. Continue with the Windows form created in the previous hands-on tutorial.
Drag-and-drop a PictureBox control onto the right of the existing controls.
2. Verify that the Image property of the PictureBox control has the default value
None.
Running Application
with Data-bind
PictureBox Control
31
Associating the Picture Column and Testing
3. Drag-and-drop the Picture column under the student table node from the
Data Sources Window onto the PictureBox control.
4. Press Ctrl + F5 to run the application. Test the data binding for PictureBox by
navigating through student records using the ToolStrip.
Running Application
with Data-bind
PictureBox Control
32
Property Window Review
5. Re-open the Property Window for the PictureBox control and review its
Image property.

It is now associated with the Picture column from the TblStudentBindingSource.
Data-bind Image Property for the PictureBox Control
33
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
34
Adding the Related Transcript Table

How-to: Display Related Data on a Windows Form
1. In the Data Sources Window, expand the student table node and select the
transcript table node. Drag-and-drop it onto the bottom of Form2.
Adding Related Tables from
the Data Sources Window
Component Tray
35
Editing the Transcript DataGridView
2. Select the transcript DataGridView and click its smart tag to view the Tasks
list. Select the Edit Column option from the list to open the Edit Columns
dialog box.
Invoking DataGridView’s Edit Columns Dialog Box
36
Editing the Transcript DataGridView (cont.)
3. Select the StudentID column and click Remove to delete the column.

In general, we can use the Edit Columns dialog box to edit properties of existing
columns, such as column heading, width, and more.
Removing StudentID Column from the DataGridView Control
37
Editing the Transcript DataGridView (cont.)
4. Select the DataGridView and navigate to the Property Window.
5. Select the AlternatingRowsDefaultCellStyle property and click the Build
button (…) to edit the alternating cell style.
Styling Alternate Rows
of a DataGridView Control
38
Editing the Transcript DataGridView (cont.)
6. Choose the BackColor and ForeColor properties in the CellStyle Builder
dialog box as shown below.
Setting BackColor and ForeColor Properties
39
Testing the Application
7. Press Ctrl + F5 to run the application. Test the parent-child relationship by
navigating through student records using the ToolStrip.
Running Application with
Parent-Child Relationship
40
Property Window Review
8. Select the TblStudentBindingSource object (parent) from the Component
tray and open the Property Window.


Note that the DataSource property of this object is set to the UniversityDataSet.
Also, the DataMember property is set to the tblStudent data table.
DataSource Property of Parent BindingSource
41
Property Window Review (cont.)
9. Now select the TblTranscriptBindingSource object (child) from the
Component tray and open the Property Window.


Note that the DataSource property of this object is set to the
TblStudentBindingSource.
Also, the DataMember property is set to tblStudenttblTranscript, which is the
name of the Data Relation object that relates parent and child tables.
DataSource Property of Child BindingSource
42
Code Review

Since we added one more table on the form, Visual Studio added one
more line of code.
– Executes the appropriate SQL query to fill the tblTranscript data table.
Form2_Load Event Populating the Transcript and Student Tables
43
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
44
DataGridView Control

The DataGridView control is one of the most used data controls
– We can use it to:






Display data
Format data
Sort data
Update and delete data
Select and navigate through data records
DataGridView Tasks:
– We can use the smart tag to:
 Access the DataSource property of the control
 Add a new column to the column collection
 Enable or disable edit, delete, and insertion operations
45
Sorting with DataGridView

DataGridView controls may be sorted by clicking any column heading in
the grid
– Click repeatedly to toggle sorting order (ascending/descending)
– A small triangular icon appears in the column when sorted
Sorting Data by DeptID Column in Descending Order
46
Data Binding

Binding data to the DataGridView control is intuitive and straightforward
– Specify data source by setting the DataSource property to a BindingSource
– Set DataMember property for specific tables/queries
DataSource and DataMember Properties of a DataGridView Control
47
DataGridView: In Depth
Name
Description
Columns
Gets a collection that contains all the columns in the control.
CurrentCell
Gets or sets the currently active cell.
CurrentRow
Gets the row containing the current cell.
DataMember
Gets or sets the name of the table in the data source for which the grid is
displaying data.

DataSource
Gets or sets the data source that the grid is displaying data for.
Item
Gets or sets the cell located at the intersection of the specified row and column.
Rows
Gets a collection that contains all the rows in the grid.
Additional properties:
– BackColor, BackgroundColor, ColumnCount, Font, ForeColor, Name,
ReadOnly, RowCount, Visible, Width
48
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
49
Hands-On Tutorial: Creating a Search Form

Often we are not interested in viewing an entire table of data
– Prefer to display only the data that satisfies some specified criteria
– We can do this using search forms in a database application

A parameterized query takes in some criteria as parameters and
retrieves records that satisfy the criteria
– Improve the efficiency of database applications
– Fetch only the portion of the data that interests us
50
Adding a Parameterized Query

How-to: Create a Search Form
1. Add a form, Form3, to the DatabaseConnectivity application.
2. Drag and drop tblStudent from the DataSources Window to the form. This
creates a DataGridView control named TblStudentDataGridView.
3. Choose the Add Query option from the Tasks list of the DataGridView.
Adding a Query to a TableAdapter Through DataGridView
51
Adding a Parameterized Query (cont.)
4. This opens the Search Criteria Builder dialog box. Name the new parameter
query FillByDept. Enter the SQL query as shown below in the Query Text
area to construct a parameterized query.
Adding Queries in
Search Criteria Builder
Dialog Box
52
Adding a Parameterized Query (cont.)
5. Click the Query Builder button in the Search Criteria Builder dialog box.
6. Click the Execute Query button to test the query.
Working with the
Query Builder to
Design SQL Queries
53
Adding a Parameterized Query (cont.)
7. A Query Parameters dialog box opens. Test the query with the example
“CISE” for the DeptID parameter value and click OK.
Assigning a Sample Value to a Query Parameter
8. Preview the results of the query in the Query Builder itself. Note that all the
records that are displayed have CISE as the DeptID. Click OK.
54
Adding a Parameterized Query (cont.)
9. We have now added a parameterized query, FillByDept, to the
TblStudentTableAdapter. This automatically creates the ToolStrip control for
DeptID input at the top of Form3.

We can also see that a ToolStrip control has been added to the Component tray.
A ToolStrip Control for a Parameterized Query
55
Preview Data for Newly Added Query
10. Use the DataGridView’s smart tag to view its Tasks list, and choose the
Preview Data option to open a dialog box.
11. Choose the query FillByDept from the drop-down list as shown below.
Selecting a Query in the Preview Data Dialog Box
56
Preview Data for Newly Added Query (cont.)
12. Provide the testing parameter for the query as “CISE” and click Preview. The
dialog box resembles below.
The Preview Data Dialog Box in Action
57
Testing the Application
13. Set Form3 as the start-up form of the application, and press Ctrl + F5 to run
the application.

Test the search or filtering functionality by entering different DeptIDs in the
FillByDept ToolStrip.
Running Form3 with the Search Functionality
58
Code Review
14. Open the Code Window for Form3 by double-clicking on the form.


Note the Visual Studio auto-generated the Click event.
Executes the FillByDept query of the TblStudentTableAdapter and fills the
tblStudent data table of the UniversityDataSet.
Executing Parameterized SQL Statements
59
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
60
The Query Builder

The Query Builder dialog box helps us build SQL queries
– Divided into four horizontal segments (listed from top to bottom):
 Table Pane: Displays and allows the addition or deletion of DataTables and their
relationships
 Design Grid: Specifies the sorting order, filter criteria, group by, and output value
for the fields being displayed
 SQL View: Displays the SQL statement as we build the query in the Design Grid
 Preview: Displays a preview of the query output
61
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
62
Linking the Department Table

How-to: Create a Look-up Table
1. Drag tblDepartment from the Data Sources Window directly onto the DeptID
ComboBox control on Form2.
2. Note that the DataSource property of the DeptID ComboBox control is set to
TblDepartmentBindingSource.
Creating a
Department
Look-up Table
(a)
Component (b)
Tray
63
Linking the Department Table (cont.)
3. Set the DisplayMember property of the DeptID ComboBox control to Name
and verify that the ValueMemeber property is set to the DeptID column.

The new Component tray objects will query and bring the names of the
departments as a list into the DeptID ComboBox control.
64
Testing the Application
4. Set Form2 as the start-up form, and press Ctrl + F5 to run the application.
5. Navigate through the student records.


Note that the ComboBox displays the department to which the student belongs.
Use the drop-down arrow on the ComboBox to see the list of all the departments.
Running Application
with a Look-up Table
65
Property Window Review
6. Open the tasks list for the DeptID ComboBox control.

Note the values for all properties of the control.
Tasks for ComboBox with a Lookup Table
66
Property Window Review (cont.)
7. Open the Property Window for DeptID ComboBox control and locate its Data
Binding section.

Note the SelectedValue property value.
Property Window for DeptID ComboBox Control
67
Code Review

The auto generated code for the lookup table is very simple.
– The only addition to the code is a call to the Fill method of
TblDepartmentTableAdapter (lines 25-26).
Form2_Load Event Showing Fill Method for Look-up Table
68
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
69
Data Binding Properties of a ComboBox Control

There are four main data binding properties of a ComboBox:
Data Source
Set it to the BindingSource object that will provide data for the ComboBox.
Unlike DataGridView, BindingSource for ComboBox should contain a single
table (simple binding).
Display Member
Set it to the field from the data source of a ComboBox that should be
displayed to the user.
Value Member
Set it to the field from the data source from which the ComboBox should get
its value. This value can be accessed in code through the property
ComboBox.SelectedValue.
Selected Value
The value of a selection in the ComboBox. This property can be bound to any
field in the project’s DataSet as long as its value matches one or more values
from the ComboBox’s ValueMember. For example, we have the department
table as the data source of the ComboBox with DeptID as the ValueMember.
The SelectedValue property is set to the DeptID from the student table.
70
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
71
In-Class Assignment

Develop an application that displays the list of faculty from the University
database
– Display on both:
 DataGridView control
 Individual controls
– Show a faculty picture in the PictureBox control
– Add a look-up table for the DeptID in an individual control on the form
– Add search functionality to the form to display only those faculty records for
which:
 Query: “The salary is greater than the user-entered salary value and the
department is the department specified by the user.”
 Hint: Add a parameter query to the TableAdapter with two parameters
72
Overview

14.1 Introduction

14.2 Database Applications Overview

14.3 Hands-On Tutorial: Creating a Simple Database Application

14.4 Auto-Created Objects in the Component Tray

14.5 Hands-On Tutorial: Displaying Data in Individual Windows Controls

14.6 Hands-On Tutorial: Binding Data to Existing Controls

14.7 Hands-On Tutorial: Displaying Related Data on a Windows Form

14.8 DataGridView Control

14.9 Hands-On Tutorial: Creating a Search Form

14.10 The Query Builder

14.11 Hands-On Tutorial: Creating a Look-up Table

14.12 Data Binding Properties of a ComboBox Control

14.13 In-Class Assignment

14.14 Summary
73
Summary

Database applications can be roughly divided into three types:
– Display-oriented
– Transaction-oriented
– Communication-oriented

The database application development process can be summarized into
the following steps:
1.
2.
3.
4.
5.
6.
Connect to the database using a Connection object
Fetch data using database queries in the TableAdapter object
Temporarily store the results in a DataSet object
Display data on a Windows form by binding Windows controls to a DataSet
Edit data in the application
Save data back in the database
74
Summary (cont.)

We walked through the process of building a simple database application
displaying the student table fields on the DataGridView control.
– We reviewed the auto-generated code and auto-set properties by Visual
Studio.

We also showed how the same data and columns can be displayed in
individual controls on a form.
– We then extended this application to bind the PictureBox to the picture
column of the student table.

We further enhanced the application by adding a related transcript table
to the form.
– Used to display the courses and grades for each student record as we
navigate through them.
75
Summary (cont.)

We have added a search or filter function to the form.
– Displays only those student records belonging to the department specified by
us in the ToolStrip.

Finally, we have added a look-up table for the department field of the
student table.
– Allows us to list all the department names via a drop-down list.
76