vbnet5
TRANSCRIPT
-
7/31/2019 vbnet5
1/13
Getting Started With ADO.NET
-
7/31/2019 vbnet5
2/13
ADO.NET ADO was a good architecture but as the language changes so is the
technology. ADO was a connected data access, which means that
when a connection to the database is established the connection
remains open until the application is closed.
ADO.NET is a data-access technology that enables applications to
connect to data stores and manipulate data contained in them in
various ways. It is based on the .NET Framework and it is highly
integrated with the rest of the Framework class library.
The ADO.NET API is designed so it can be used from all programminglanguages that target the .NET Framework, such as Visual Basic, C#,
J# and Visual C++.
-
7/31/2019 vbnet5
3/13
ADO.NET Data Architecture
-
7/31/2019 vbnet5
4/13
AccessingData In Connected Ado.Net
ArchitectureIn connected architecture database connection need to open andclose explicitly. While accessing data, the respective database
need to be connected.
-
7/31/2019 vbnet5
5/13
In disconnected architecture database connection not requireafter data has retrieved and stored into a dataset. We need tore-connect the database when we want to update anychanges into database, or require new updated data fromdatabase
Accessing Data In Disconnected
Ado.Net Architecture
-
7/31/2019 vbnet5
6/13
The Connection object creates the connection to the database.Microsoft Visual Studio .NET provides two types ofConnection classes. The Connection object contains all of the
information required to open a connection to the database.
Connection Object
Dim cnNorthwind as New
System.Data.SqlClient.SqlConnection("User ID=sa;
Password=2389; Initial Catalog=Northwind; Data
Source=London; Connection TimeOut=60;" )
-
7/31/2019 vbnet5
7/13
Command objects are used to execute commands to adatabase across a data connection. The Commandobjects can be used to execute stored procedures on
the database, or return complete tables directly.
Command Object
Dim sql As String = "SELECT UnitsInStock FROM
Products WHERE ProductID = @ProdID"
Dim cmdProducts As SqlCommand (sql, cnNorthwind)
-
7/31/2019 vbnet5
8/13
Command objects provide three methods that are used to
execute commands on the database: ExecuteNonQuery()
Executes commands that have no return values such asINSERT, UPDATE or DELETE
ExecuteScalar()
Returns a single value from a database query
ExecuteReader()
Returns a result set by way of a DataReader object
Command Object
-
7/31/2019 vbnet5
9/13
The DataReader object provides a forward-only, read-only,connected stream recordset from a database.
Because only one row is in memory at a time, the DataReader
provides the lowest overhead in terms of systemperformance but requires the exclusive use of an openConnection object for the lifetime of the DataReader.
DataReader Object
Dim rdrProducts As SqlDataReader
rdrProducts = cmdProducts.ExecuteReader()
-
7/31/2019 vbnet5
10/13
The DataAdapter is the class at the core of ADO .NET'sdisconnected data access. It is essentially the middlemanfacilitating all communication between the database and aDataSet. The DataAdapter is used either to fill a DataTable orDataSet with data from the database with it's Fill method.
After the memory-resident data has been manipulated, theDataAdapter can commit the changes to the database bycalling the Update method.
DataAdapter Object
Dim cnNorthwind As New SqlConnection()
Dim daProducts As New SqlDataAdapter(SELECT * FROM
Products,cnNorthwind)
-
7/31/2019 vbnet5
11/13
The dataset is a disconnected, in-memory representation of data. It can beconsidered as a local copy of the relevant portions of the database. TheDataSet is persisted in memory and the data in it can be manipulated andupdated independent of the database. When the use of this DataSet isfinished, changes can be made back to the central database for updating.
The data in DataSet can be loaded from any valid data source like MicrosoftSQL server database, an Oracle database or from a Microsoft Access
database.
DataSet Object
Dim dsCustomers As New DataSet()
daCustomers.Fill(dsCustomers, "Customers")
-
7/31/2019 vbnet5
12/13
1. Typed
2. Untyped
Typed dataset
Is derived from the DataSet class and has an associated XML schema, whichis created at the time of the creation of the dataset.
Can be customized after creation.
Supports Intellisense and auto-completion for the elements of the syntax whilewriting code.
Untyped dataset
Does not have any associated XML schema, therefore, the structure of anuntyped dataset is not known at the compile time.
Represents tables and columns as collections.
Does not support Intellisense and auto-completion for the elements of thesyntax.
DataSet Types
-
7/31/2019 vbnet5
13/13
DataSet Object