VB .net tutorial - 5
-
Upload
mathes99994840202 -
Category
Documents
-
view
230 -
download
0
Transcript of VB .net tutorial - 5
-
8/14/2019 VB .net tutorial - 5
1/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 1 of 30
Objectives
In this lesson, you will learn to:
Identify the need for ADO.NET
Identify the features of ADO.NET
Identify the components of the ADO.NET object model
Connect to a database by creating a data adapter
Access a database through a dataset
Preview the data adapter result
-
8/14/2019 VB .net tutorial - 5
2/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 2 of 30
ADO.NET
Is a model used by Visual Basic .NET applications to
communicate with a database for retrieving, accessing, and
updating data.
Uses a structured process flow to interact with a database.
-
8/14/2019 VB .net tutorial - 5
3/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 3 of 30
Features of ADO.NET
Disconnected data architecture Applications connect to
the database only while retrieving and updating data.
Data cached in datasets ADO.NET is based on adisconnected data structure. Therefore, the data is retrieved
and stored in datasets.
Data transfer in XML format ADO.NET uses XML for
transferring information from a database into a dataset andfrom the dataset to another component.
Interaction with the database is done through data
commands.
-
8/14/2019 VB .net tutorial - 5
4/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 4 of 30
Just a Minute
List the features of ADO.NET.
-
8/14/2019 VB .net tutorial - 5
5/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 5 of 30
ADO.NET Object Model
DATASET
VISUAL BASIC
.NET
APPLICATION
(WINDOWS/
WEB FORM)
DATA PROVIDER
Accessing
retrieved data
Accessing retrieved
data
CONNECTION
COMMAND
DATA ADAPTER
DATA READER
Establishesconnection with
the database
Filling datasetwithdata
Transfers data to
the dataset and
reflects the
changes made in
the dataset to the
database
DATABASE
Retrieves data in a
read-only,
forward only mode
Executes a
command to retrieve
data from thedatabase
-
8/14/2019 VB .net tutorial - 5
6/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 6 of 30
ADO.NET Object Model (Contd.)
Data from a database can be assessed through:
A dataset
A DataReader object
-
8/14/2019 VB .net tutorial - 5
7/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 7 of 30
Key Components of the ADO.NET Model
Data Provider
Is used for connecting to a database, retrieving data,
and storing the data.
Is of two types:
OLE DB data provider
SQL Server data provider
-
8/14/2019 VB .net tutorial - 5
8/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 8 of 30
Just a Minute
Identify the two types of data providers and list the difference
between them.
-
8/14/2019 VB .net tutorial - 5
9/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 9 of 30
Components of a Data Provider
Connection
Used to establish a connection with a data source
Some commonly used properties and methods:
ConnectionString property
Open()method
Close()method
State property
-
8/14/2019 VB .net tutorial - 5
10/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 10 of 30
Components of a Data Provider (Contd.)
Data adapter
Creates a dataset and updates the database.
Handles data transfer between the database and the
dataset through its properties and methods.
Displays the data through the process of table mapping.
Are of two types:
SqlDataAdapter
OleDbDataAdapter
-
8/14/2019 VB .net tutorial - 5
11/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 11 of 30
Just a Minute
What is the function of a data adapter?
-
8/14/2019 VB .net tutorial - 5
12/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 12 of 30
Components of a Data Provider (Contd.)
Data command
Is a SQL statement or a stored procedure that is used to
retrieve, insert, delete, or modify data from a datasource.
Is an object of the OleDbCommand orSQLCommand
class.
-
8/14/2019 VB .net tutorial - 5
13/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 13 of 30
Components of a Data Provider (Contd.)
Data reader
Is used to retrieve data from a data source in a
read-only and forward-only mode.
Stores a single row at a time in the memory.
Commonly used methods:
Read()
Close()
NextResult()
-
8/14/2019 VB .net tutorial - 5
14/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 14 of 30
Dataset
Is a disconnected, cached set of records that are retrieved
from a database.
Is present as a DataSet class in the System.Datanamespace.
Has its own object model.
-
8/14/2019 VB .net tutorial - 5
15/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 15 of 30
Dataset Object Model
DataRow DataColumn
DATASET
DataRelationCollection
DataRelation
DataTableCollection
DataTable
DataRowCollection DataColumnCollection
ExtendedProperties
DataVi ew PrimaryKe y
-
8/14/2019 VB .net tutorial - 5
16/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 16 of 30
Just a Minute
What are the various components of a dataset?
-
8/14/2019 VB .net tutorial - 5
17/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 17 of 30
Problem Statement 5.D.1
The call center application needs to provide the facility of
viewing the customer details for the Sales department.
-
8/14/2019 VB .net tutorial - 5
18/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 18 of 30
Task List
Identify the data that needs to be displayed.
Identify the method for creating a data adapter.
Identify the type of dataset to be created.
Create a data adapter.
Create a dataset.
Preview the database records.
-
8/14/2019 VB .net tutorial - 5
19/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 19 of 30
Task 1: Identify the data that needs to be displayed.
Result:
As per the given problem statement, the data to be
displayed is as follows:
CustID
FName
LName
Address
Phone
email
-
8/14/2019 VB .net tutorial - 5
20/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 20 of 30
Task 2: Identify the method for creating a dataadapter.
There are three methods to create a data adapter:
Manually
Through a wizard
Using the Server Explorer window
Result:
In the given problem statement, you will create a data
adapter by using Data Adapter Configuration Wizard since it
lets you create a data adapter with minimum steps.
-
8/14/2019 VB .net tutorial - 5
21/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 21 of 30
Just a Minute
What are the different methods of creating a data adapter?
-
8/14/2019 VB .net tutorial - 5
22/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 22 of 30
Task 3: Identify the type of dataset to be created.
Datasets are of two types:
Typed
Untyped
Typed dataset
Is derived from the DataSet class and has an
associated XML schema, which is created at the time ofthe creation of the dataset.
Can be customized after creation.
Supports Intellisense and auto completion for theelements of the syntax while writing code.
-
8/14/2019 VB .net tutorial - 5
23/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 23 of 30
Task 3: Identify the type of dataset to be created.(Contd.)
Untyped dataset
Does not have any associated XML schema, therefore,the structure of an untyped dataset is not known at thecompile time.
Represents tables and columns as collections.
Does not support Intellisense and auto completion forthe elements of the syntax.
Result:
Since the structure of the data is known at compile time,
you will create a typed dataset for the given problemstatement.
-
8/14/2019 VB .net tutorial - 5
24/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 24 of 30
Just a Minute
What is the difference between typed and untyped dataset?
-
8/14/2019 VB .net tutorial - 5
25/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 25 of 30
Task 4: Create a data adapter.
Task 5: Create a dataset.
Task 6: Preview the database records.
-
8/14/2019 VB .net tutorial - 5
26/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 26 of 30
Problem Statement 5.P.1
An application needs to be created that allows the Diaz
Telecommunications Sales Manager to preview the customer
order details from the database. In addition, for each order,
percentage of the cost of a product given as advance needs tobe previewed.
-
8/14/2019 VB .net tutorial - 5
27/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 27 of 30
Summary
In this lesson, you learned that:
ADO.NET is a data access programming model for
accessing the data stored in a database from a .NETapplication.
ADO.NET has the following features:
A disconnected data architecture
Data cached in datasets
The use of XML format for data transfer
Database operations done through data commands
-
8/14/2019 VB .net tutorial - 5
28/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 28 of 30
Summary (Contd.)
ADO.NET consists of the following components:
Data Provider Used for connecting to a database,
retrieving data, storing the data in a dataset, andupdating the database.
Data Adapter A data adapter is integral to the
working of the ADO.NET model since data transfer to
and from the database is done through a data adapter.
Dataset A dataset is a disconnected cached set of
records that are retrieved from the database.
A data adapter communicates with a database through datacommands. These data commands use parameters for
execution.
-
8/14/2019 VB .net tutorial - 5
29/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 29 of 30
Summary (Contd.)
After a dataset has been created, a data adapter uses the
process of table mapping to map the columns in the
database table with the dataset columns.
A data adapter can be created by using any of the following
methods:
Manually
Through a wizard
By using Server Explorer
-
8/14/2019 VB .net tutorial - 5
30/30
Working with ADO.NET
NIIT Working with ADO.NET/Lesson 5/Slide 30 of 30
Summary (Contd.)
Datasets are of two types:
Typed datasets A typed dataset is derived from the
DataSet class and has an associated schema. Untyped datasets An untyped dataset does not have
any associated XML schema. The tables and columns
in an untyped dataset are represented as collections.