Professional Documents
Culture Documents
ASP Chap5
ASP Chap5
NET
● Overview of ADO.NET Objects
● Create and retrieve Database Connections
● SqlDataSource Controls
● ASP.NET Data-Bound Controls
● GridView, Repeater, DataList, Details View, Form View
● Overview of ADO.Net Objects:
ADO.Net Architecture:-
The most important concept in ADO.NET architecture is “Data Provider”. Data Provider provides
access to data sources (SQL Server, Access, Oracle). In short, it provides an object to achieve
functionalities like opening and closing connection, retrieve data, and update data. In the below figure,
you can see the four main sections of a data provider:
● Connection.
● Command object (this is the object for using Stored Procedures).
● Data Adapter (this object acts as a bridge between the data store and the dataset).
● Data Reader (this object reads data from the data store in forward only mode).
● DataSet object represents disconnected and cached data. If you see the diagram, it is not in
direct connection with the data store (SQL Server, Oracle, etc.) rather it talks with the data
adapter, who is responsible for filling the dataset. The dataset can have one or more datatables
and relations.
● The DataView object is used to sort and filter data in the datatable.
ADO.Net:-
ADO.NET is the new database technology used in .NET platform. ADO.NET is the next step
of Microsoft ActiveX Data Objects (ADO). It shares much of the ADO functionality. The ADO.NET
covers the classes in the System.Data namespace. ADO.NET is a set of classes that expose the data
access services of the .NET Framework.
✔ ADO stands for ActiveX Data Objects
✔ ADO.NET is a database technology of .NET Framework used to connect application system
and database server.
✔ ADO.NET is a part of the .NET Framework
✔ ADO.NET consists of a set of classes used to handle data access
✔ ADO.NET uses XML to store and transfer data among applications, which is not only an
industry standard but also provide fast access of data for desktop and distributed applications.
✔ ADO.NET is scalable and interoperable
ADVANTAGES OF ADO.NET
1) Interoperability. ADO.NET uses XML as the format for transmitting data from a database to a
local memory.
2) Maintainability. When an increasing number of users work with an application, the increased use
can strain resources. By using n-tier applications, you can spread application logic across
additional tiers. ADO.NET architecture uses local in-memory caches to hold copies of data,
making it easy for additional tiers to trade information.
3) Programmability. The ADO.NET programming model uses strongly typed data. Strongly typed
data makes code more concise and easier to write because Microsoft Visual Studio .NET provides
statement completion.
4) Performance. ADO.NET helps you to avoid costly data type conversions because of its use of
strongly typed data.
5) Scalability. The ADO.NET programming model encourages programmers to conserve system
resources for applications that run over the Web. Because data is held locally in in memory caches,
there is no need to retain database locks or maintain active database connections for extended
periods.
CONNECTED VS DISCONNECTED: For much of the history of computers, the only environment
available was the connected environment. In many situations, people do not work entirely in a
connected or disconnected environment, but rather in an environment that combines the two
approaches.
Connected: A connected environment is one in which an application is constantly connected to a data
source. A connected architecture has following advantages:
a) A secure environment is easier to maintain.
b) Concurrency is easier to control.
c) Data is more likely to be current than in other scenarios.
A connected scenario has the following disadvantages:
a) It must have a constant network connection.
b) Scalability
Disconnected: A disconnected environment is one in which an application is not constantly connected
to a source of data. Users can take a subset of data with them on a disconnected computer, and then
merge changes back into the central data store.
A disconnected environment provides the following advantages:
a) You can work at any time that is convenient for you, and can connect to a data source at any
time to process requests.
b) Other users can use the connection.
c) A disconnected environment improves the scalability and performance.
A disconnected environment has the following disadvantages:
● Data is not always up to date.
● Change conflicts can occur and must be resolved.
.NET DATA PROVIDER
A .NET data provider is used for connecting to a database, executing commands, and retrieving
results. Those results are either processed directly, or placed in an ADO.NET DataSet in order to be
exposed to the user in an ad-hoc manner, combined with data from multiple sources, or remoted
between tiers. The .NET data provider is designed to be lightweight, creating a minimal layer between
the data source and your code, increasing performance without sacrificing functionality. The
ADO.NET object model includes the following data provider classes:
1. SQL Server .NET Data Provider
2. OLE DB .NET Data Provider
3. Oracle .NET Data Provider
4. ODBC .NET Data Provider
5. Other Native .NET Data Provider
1) SQL Server Data Provider: To use the SQL Server .NET Data Provider, you need to include the
System.Data.SqlClient namespace in your applications. Using this provider is more efficient than
using the OLE DB .NET Data Provider because it does not pass through an OLE DB or Open
Database Connectivity (ODBC) layer. It provides optimized access to SQL Server 2000 and SQL
Server 7.0 databases.
2) OLE DB Data Provider: To use the OLE DB .NET Data Provider, you need to include the
System.Data.OleDb namespace in your applications. .NET Provides access to SQL Server
versions 6.5 and earlier. It also provides access to other databases, such as Oracle, Sybase,
DB2/400, and Microsoft Access.
3) Oracle .NET Data Provider: To use the Oracle Database, a native Oracle .NET data driver is the
best choice. To use the Oracle .NET Data Provider, you need to include the
System.Data.OracleClient namespace in your applications. Oracle itself also provides a .NET
data provider, referenced as Oracle.DataAccess.Client. This is a separate download that you have
to get from Oracle. Whether you use a .NET data provider from the database vendor or just use the
one provided with the .NET framework is your choice.
4) ODBC .NET Data Provider: If you have a data source for which no native or OLE DB provider
is available, the ODBC .NET data provider is good alternative because most database provide an
ODBC interface. It is referenced with this using directive: System.Data.Odbc
5) Other Native .NET Data Provider: If there is a native .NET data provider available specifically
for your database, then you may want to use that .NET data provider instead. Many other database
vendors and third-party companies provide native.
.NET data providers; the choice between using the native providers and using something
generic like the ODBC provider will depend on your circumstances. If you value portability over
performance, then go generic. If you want to get the best performance or make the best use of a
particular database„s features, go native.
Providers: An ADO.NET provider is a class that can communicate with a specific type of database or
data store, such as SQL Server, Oracle, MS-Access, etc. database. The providers included with the
.NET Framework are:
1. SqlServer:- The .NET Framework Data Provider for SQL Server in the System.Data.SqlClient
namespace. This provider is the default for the SqlDataSource control.
2. OleDb:- The .NET Framework Data Provider for OLE DB in the System.Data.OleDb
namespace.
3. Odbc:- The .NET Framework Data Provider for ODBC in the System.Data.Odbc namespace.
Connection Strings: A connection string provides the information that a provider needs to
communicate with a particular database. Depending on the provider, a connection string usually
supplies the server or location of the database server, the database name and authentication
information.
Creating Connection:
1) Open Visual Studio, select “Server Explorer” Connect to Database Add Connection. Window
will open.(like the following image.)
● DetailsView:
The DetailsView control was introduced with ASP.NET 2.0. The DetailsView control uses a
table-based layout where each field of the data record is displayed as a row in the control. Unlike the
GridView control, the DetailsView control displays one row from a data source at a time by rendering
an HTML table. The DetailsView supports both declarative and programmatic data binding. The
DetailsView control is often used in master-detail scenarios where the selected record in a master
control determines the record to display in the DetailsView control. It shows the details for the row in
a separate space. We can customize the appearance of the DetailsView control using its style
properties. Alternatively, we can also use Cascading Style Sheets (CSS) to provide styles to a
DetailsView control. A DetailsView control appears as a form of recording and is provided by
multiple records as well as insert, update and delete record functions.
The DetailsView control supports the following features:
● Tabular rendering
● Supports column layout, by default two columns at a time
● Optional support for paging and navigation.
● Built-in support for data grouping
● Built-in support for edit, insert and delete capabilities
● FormView: The FormView was introduced with ASP.NET 2.0. The FormView control renders a
single data item at a time from a data source, even if its data source exposes a multiple records data
item from a data source. It allows for a more flexible layout when displaying a single record. The
FormView control renders all fields of a single record in a single table row. In contrast, the
FormView control does not specify a pre-defined layout for displaying a record. Instead, you
create templates that contain controls to display individual fields from the record. The template
contains the formatting, controls and binding expressions used to lay out the form. When using
templates, we can place any control such as a dropdown list, checkbox and we can even place
tables and rich controls like a GridView and so on. A FormView is a databound control used to
insert, display, edit, update and delete data in ASP.NET that renders a single record at a time. A
FormView control is similar to a DetailView in ASP.NET but the only difference is that a
DetailsView has a built-in tabular rendering whereas a FormView requires a user-defined template
to insert, display, edit, update and delete data.
The FormView control supports the following features:
● Template driven
● Supports column layout
● Built-in support for paging and grouping
● Built-in support for insert, edit and delete capabilities
*-*-*