Giáo Viên: Nguyễn Văn Thắng.3- 3 OLEDB UDA concept to data from any source using the same programming tools Visual Basic and Database Applications ADO.NET set of objects to refer to data
Trang 1Chapter 3
Windows Database
Applications
Advanced Programming
Using Visual Basic.NET
Universal Data Access
(UDA)
multiple providers
application on any type of computer
Visual Basic and Database Applications
Trang 2Giáo Viên: Nguyễn Văn Thắng.
3- 3
OLEDB
UDA concept
to data from any source using the same
programming tools
Visual Basic and Database Applications
ADO.NET
set of objects to refer to data from any
source
with common data representation (data
types) from multiple sources
ActiveX Data Objects à ADO
ActiveX Data Objects à ADO
Trang 3Giáo Viên: Nguyễn Văn Thắng.
3- 5
ADO.NET
(Extensible Markup Language)
datasets provide for
– Flexibility à adapt to changes in data or
presentation tier
– Scalability à handle increases in the number
of users and servers
Visual Basic and Database Applications
XML is an industry standard
format for storing and transferring data over multiple platforms.
XML is an industry standard
format for storing and transferring data over multiple platforms.
ADO.NET Components
• Data Providers – manipulate the data using
SQL statements or stored procedures
– SQLClient à for SQL Server
– OleDbClient à for all other database formats
Visual Basic and Database Applications
Trang 4Giáo Viên: Nguyễn Văn Thắng.
3- 7
ADO.NET Components
• DataSet Objects à holds a copy of the
data in memory
from many sources
DataSet objects the same
DataTable objects
Visual Basic and Database Applications
A Sample DataTable
one entity
of data à field
Trang 5Giáo Viên: Nguyễn Văn Thắng.
3- 9
DataTable Characteristics
fields) uniquely identifies each record
tables
using a foreign key
Visual Basic and Database Applications
The DataSet Object Model
Visual Basic and Database Applications
DataSet
DataTable Collection DataTable
DataRowCollection DataColumnCollection ParentRelations ChildRelations ConstraintCollection DataView
DataRelationCollection
Trang 6Giáo Viên: Nguyễn Văn Thắng.
3- 11
Data Provider Objects
• Connection object – link to a data source
• DataAdapter object – handles retrieving
and updating data in a DataSet object
• Command object – storeprocedure and
executes SQL statements
• DataReader object –
for read-only access
Visual Basic and Database Applications
A NET data provider is a set
of components designed for fast access and manipulation of data.
A NET data provider is a set
of components designed for fast access and manipulation of data.
Use the DataSet object
connection
Trang 7Giáo Viên: Nguyễn Văn Thắng.
3- 13
.NET Data Provider Objects
Visual Basic and Database Applications
SelectCommand InsertCommand UpdateCommand DeleteCommand
Connection
.NET Data Provider
Command
Data Adapter
DataReader
XML Data
tags
Visual Basic and Database Applications
XML is an industry standard
format for storing and transferring data.
XML is an industry standard
format for storing and transferring data.
<au_id>172-32-1176</au_id>
Trang 8Giáo Viên: Nguyễn Văn Thắng.
3- 15
XML Schema File
constraints
in the Solution Explorer
Visual Basic and Database Applications
XML Data Format
Advantages
handling of data
executes faster
Trang 9Giáo Viên: Nguyễn Văn Thắng.
3- 17
Microsoft Database Files
databases
version of SQL Server
MSDE and SQL Server
Obtaining Data
data source
and updating the data
bind controls to the fields in the DataSet
object
MSDE and SQL Server
Trang 10Giáo Viên: Nguyễn Văn Thắng.
3- 19
Obtaining Data
MSDE and SQL Server
Connection Data Adapter
Data
Web Form
Windows Form
Use Server Explorer to select and drag fields to the form
Connection and adapter components are automatically added to the component tray.
Use Server Explorer to select and drag fields to the form
Connection and adapter components are automatically added to the component tray.
Display the DataSet in the
DataGrid
Trang 11Giáo Viên: Nguyễn Văn Thắng.
3- 21
Populating Combo Boxes
with Data
property
– Connects to the dataset
property
– Connects to the field
name
load the list
Displaying Data in Individual Fields
daEmployee.Fill(DsEmployee1)
Sorting Data for the ListBox
– Virtual view of an
existing table
from the Data section of
the toolbox
Displaying Data in Individual Fields
Trang 12Giáo Viên: Nguyễn Văn Thắng.
3- 23
Creating a Parameterized
Query
statement to specify the criteria
Displaying Data in Individual Fields
SELECT emp_id, fname, minit, lname, job_id, job_lvl, hire_date FROM employee
WHERE lname = @lname
SELECT emp_id, fname, minit, lname, job_id, job_lvl, hire_date FROM employee
WHERE lname = @lname
Using the Query Builder
Trang 13Giáo Viên: Nguyễn Văn Thắng.
3- 25
Binding Individual Controls
to Data Fields
Displaying Data in Individual Fields
Adding an Expression to the
DataSet Schema
Displaying Data in Individual Fields
Trang 14Giáo Viên: Nguyễn Văn Thắng.
3- 27
Using the ValueMember
Property of Combo Boxes
field to display in the list
unique field value
parameter
Displaying Data in Individual Fields
daEmployee.SelectCommand.Parameters(“@emp_id”).Value =
cboNames.SelectedValue.ToString
daEmployee.SelectCommand.Parameters(“@emp_id”).Value =
cboNames.SelectedValue.ToString
Multiple Tier Projects
interface
User Interface
(Form)
DataSet Connection DataAdapter
Trang 15Giáo Viên: Nguyễn Văn Thắng.
3- 29
Binding to Combo Boxes
the data view
properties from fields in the data view
Multiple Tiers
DataBindings for Multiple
Tiers (phần này sinh viên tự
tham khảo trong sách)
DataBindings.Add method
another event procedure
Multiple Tiers
ControlName.DataBindings.Add(“text”, DataSource, “FieldName”)
lblEmployeeID.DataBindings.Add(“text”, dsEmployee.Tables(“employee”), “emp_id”)
lblHireDate.DataBindings.Add(“text”, dsEmployee.Tables(0), “hire_date”)
lblEmployeeID.DataBindings.Add(“text”, dsEmployee.Tables(“employee”), “emp_id”)
lblHireDate.DataBindings.Add(“text”, dsEmployee.Tables(0), “hire_date”)