Professional Documents
Culture Documents
ADO.NET
R.SHEEBA M.SC.,M.PHIL.,
ASSISTANT PROFESSOR,
DEPARTMENT OF COMPUTER SCIENCE
MADURAI SIVAKASI NADARS PIONEER MEENAKSHI
WOMEN’S COLLEGE, POOVANTHI
Introducing ADO.NET and Data Management
Most applications need to handle data, whether it is in the form of a dataset, a text file, or a
spreadsheet. The majority of modern-day applications need to deal with various types of databases.
Therefore, to access this data the application needs to interact with various databases, such as Microsoft
ASP.NET application might use a database “behind the scenes” to retrieve information, which is then
processed and displayed in the appropriate format and location in the browser.
ADO.NET is a part of the .NET framework architecture. It is a model used by .NET
applications to communicate with a database for retrieving, accessing, and updating data.
E-Commerce Sites
Involve less structured databases that store vast quantities of information, or links to
various documents and resources.
Google Knowledge Graph
The “knowledge graph” is a database that collects millions of pieces of data about keywords people frequently
search for on the World wide web and the intent behind those keywords, based on the already available content.
With the knowledge graph, users can get information about people, facts and places that are interconnected
in one way or the other.
Google’s goal is to provide accurate information in response to users’ search queries, within the
shortest possible time.
what exactly is the Knowledge Graph? It’s Google’s systematic way of putting facts, people and
places together, to create interconnected search results that are more accurate and relevant.
just go to Google
and search for
“what is the
knowledge
graph?”
The answer is
displayed right
there – and that’s
also what the
Knowledge Graph
does.
If you do a search these days, you’ll notice that Google bolds your keywords in the meta
description.
The keywords in
the this screenshot
are bolded, even
when some of the
search terms are
missing. Google is
mainly looking at
the relevance of the
page to what the
user is seeking.
Information-based sites such as web portals
To create these tables, add all the information you need, and store it as an XML file using
ADO.NET.
Additional products used for flexibility
SQL server
The SQL Server is a relational database management system from Microsoft. The system
is designed and built is to manage and store information. The system supports various
business intelligence operations, analytics operations, and transaction processing.
SQL Server’s Enterprise Manger – Way to design and create tables in an SQL Server
database.
Characteristics of ADO.NET
Disconnected Access
Native XML
Extended Data Format
Managed Code
Data Providers
Disconnected Access
When you retrieve information from a database into an ADO.NET Dataset, the data is
stored in memory in an XML format.
We can modify values, remove rows, and add new records using XML Document Object
Model (DOM), which are available in .NET through the types in the System.Xml
namespaces.
XML File Format
Managed Code
ADO.NET is built in the managed code environment, which means it can be used easily
in other .NET applications(Such as ASP.NET programs).
Data Providers
The . Net Framework includes mainly three Data Providers for ADO.NET.
The Microsoft SQL Server , OLEDB and ODBC are the main Data Providers included in
the . Net Framework.
Extended Data Format
ADO.NET retains more information to allow you to effectively make changes without
needing to repeatedly reconnect to the database.
These changes are found in DataSet object, ADO.NET’s replacement for the Recordset.
ADO.NET allows you to add information for several interrelated tables, link them
together, disconnected relational database.
Comparing ADO and ADO.NET
The ADO.NET object model
Data Namespaces
The ADO.NET components live in five main namespaces in the .NET class library.
Namespaces Description
System.Data This namespace is the core of ADO.NET framework. DataSet is the most import
class of this namespace. It also contains classes to represent tables, columns,
rows, relation and the constraint.
System.Data.Common It provides common classes, those works as base class. These classes are used
by all data providers. Examples are DbConnection and DbDataAdapter
System.Data.OleDb It provides classes that work with OLE-DB data sources using the .NET OleDb
data provider. If you are using the Microsoft Access as a database, then
System.Data.OleDb namespace will be used. Example of these classes are
OleDbConnection, OleDbCommand
Namespaces Description
System.Data.Odbc This namespace defines classes that work with the ODBC data
sources using the .NET ODBC data provider. It is collection of
classes used to access an ODBC data source. It contains classes
such as OdbcConnection, OdbcCommand
and OdbcDataReader
System.Data.SqlClient It defines the data provider for the SQL Server database. It contains
classes that are used to access a SQL Server database. Examples are
SqlConnection, SqlCommand and
SqlDataReader
System.Data.SqlTypes This namespace provides classes for specific data types for the SQL
Server database.
The ADO.NET objects
components:
• Data Provider
• DataSet
The Data Objects
The data objects allow you to store a local, disconnected copy of data. They don’t store a connection to
a data source.
The data modelling objects
Data Provider
Selecting an appropriate data provider for a client application depends on the type of
data source being accessed. There are four .Net data providers available.
1. SQL Server: It's used to work specifically with Microsoft SQL Server. It exists in a
namespace within the System.Data.SqlClient.
2. OLE DB: It's used to work with the OLEDB provider. The System.Data.dll assembly
implements the OLEDB .NET framework data provider in the System.Data.OleDb
namespace.
3. ODBC: To use this type of provider, you must use an ODBC driver. The
System.Data.ODBC.dll assembly implements the ODBC .NET framework data provider.
This assembly is not part of the Visual Studio .NET installation.
4. Oracle: The System.Data.OracleClient.dll assembly implements the Oracle .NET
framework data provider in the System.Data.OracleClient namespace. The Oracle client
software must be installed on the system before you can use the provider to connect to
an Oracle data source.
Data Provider Components
WriteXML and ReadXML - Allow the DataSet to be serialized to an XML file and read
It contains a collection of DataRows, which contains all the data in the table.
It also provides a collection of DataColumns, which contain information about each column in the table,
and a collection of constraints, which specifies additional column metadata such as the primary key.
The DataTable class includes a Select method that allows you grab a subset of rows that match a specified
filter expression, in a specified sort order.
You can access individual values using the field name or field index.
BeginEdit, EndEdit and CancelEdit – Allows you to use edit mode to make a series of changes
to a row, and apply or cancel them all at once.
Delete – Marks a row as deleted, and hides it from the default view used for the table.
GetChildRows – Uses the table relations you have defined to get rows from a linked table.
DataColumn
It stores information about the column, such as column’s data type, its default value, and
various restrictions.
DataRelation
For example: A DataRelation could indicate that the CustomerID column in the Orders
table corresponds to the CustomerID column in the Customers table.
DataView
Each DataTable has at least one DataView, which is used for data binding.
It also allows you to format a single DataTable in more than one way by creating separate
DataView objects.
The Data Source Interaction Objects
The goal of the data source object is to create a connection and move information into a
DataSet or into a DataReader.
The simplest way of accessing a database-going straight to the source with Command
objects and retrieving read-only rows through a DataReader.
Direct Data Access with ADO.NET
Using a DataSet with ADO.NET
Sql Connection and OleDbConnection
These objects represent an SQL statement or stored procedure that you can use against a data source to retrieve,
update, or modify data.
You set information into a command using CommandType and CommandText properties.
You can add any parameters you need using SqlParameter or OleDbParameter objects.
To actually use your command, you must use a DataAdapter or use the following methods:
ExecuteNonQuery
ExecuteReader
ExecuteScalar
These are the most common methods of the SqlCommand class as follows.
ExecuteReader – Executes select SQL statements which can either be in your .NET code
or in the stored procedure. Returns a “DataReader” object.
ExecuteScalar – Executes SQL command and returns only a single value like count, sum,
first record, etc.
SqlDataReader and OleDbReader
There are two types of DataReader in ADO.NET. They are SqlDataReader and the OleDbDataReader.
The System.Data.SqlClient and System.Data.OleDb are containing these DataReaders respectively.
They are fastest way to read data when all you want to do is display in a web page.
They maintain a live connection with a data source, but they don’t allow any changes.
To get a row of information from an SqlDataReader and OleDbReader object, you use the Read
method.
SqlDataAdapter and OleDbDataAdapter
These objects, which derive from the common DataAdapter class, acts as a bridge between a Command
and a DataSet.
For example: You can create an SQL statement that selects a set of rows, create a command that
represents it, and use the SqlDataAdapter or OleDbDataAdapter object to automatically retrieve all the
matching values and insert them into a supplied DataSet.
Every DataAdapter can hold a reference to four different commands, one for each type of operation.
You set these commands through the DeleteCommand, InsertCommand, SelectCommand, and
UpdateCommand properties.
Once you have set the appropriate commands, you can use one of the following methods:
Fill – Executes the SelectCommand and places the results into the DataSet you supply.
FillSchema – Uses the SelectCommand to retrieve information about a table, such as column
constraints, and add it to a DataSet. No data rows are transferred.
Update – Scans through the supplied DataSet, and applies all the changes it finds to the data
source. In the process, it uses InsertCommand, UpdateCommand, or DeleteCommand as
required. For example: If it finds new rows that didn’t exist before, it uses the InsetCommand.
Next Topic to be continued : SQL Basics