You are on page 1of 24

CHAPTER #6

Database Programming
THE ADO.NET ARCHITECTURE
• Almost all running software needs to interact with databases.
• Ado.net for front and database interaction purpose.

• ADO.NET is a set of classes exposing data access services to .NET


programmers.
• Access to
• Relational
• Xml
• App data
• Classes found in syst.data.dll assembly
• It offers two types of architectural components.
• Connected
• Disconnected data objects
• Found under the system. Data namespace.
CONNECTED DATA OBJECTS
• relies on a consistent database connection.
• It offers the following objects
• Connection: the main, or core, object for any database-
oriented application.

• Command: handling of statements that your application


will be using to perform data-oriented tasks.
• DataReader: creating an instance of the Command object.

• Parameter: a value passed or returned to/from a stored


procedure or an argument passed to a SQL query.

• DataAdapter: bridge the gap between connected and


disconnected architectures.
DISCONNECTED DATA OBJECTS
• it offers flexible application design and helps organizations save database connections.

• Data stored locally in the form of a Dataset object.


• Data manipulation on the local device.
• Data sync back to the server.

• utilizes expensive resources like Connection in a very optimum way.


• Open late and close early.

• Ado.net offers the following objects to work with disconnected data objects.
• Dataset: core architectural component of ADO.NET to make
disconnected applications.
• contains one or more data tables.
• Is a subset of data.
• Data Table: is a row-and-column representation that provides much the
same logical view as a physical table in a database.
• Manipulate the data on the local machine.
• Data Row: consists of rows as the physical table.
• Exists in the form of DataROwcollection format.
• An enumerable collection of datarow objects.

• DataColumn: similar to the column of the physical table.


• Consist of datacolumn
• Datacolumencollection type
• DataView: it has similar purpose to a view in a database.
• a view in a databse provides
• a predefined
• organized
• or filtered set of records.
THE .NET DATA PROVIDERS

• ADO.NET consists of various data providers


• To communicate with various dbms
• Most commonly used data providers are: -
• SQL Server Data Provider
• OLEDB data provider and
• ODBC data provider
SQL SERVER DATA PROVIDER
• System.Data.SqlClient namespace.
• You can also use System.Data.OleDb but the first is more
efficient and optimized.

native network protocol


Classes Description

SqlCommand Executes SQL queries, statements, or stored


procedures
SqlConnection Represents a connection to a SQL Server database
SqlDataAdapter Represents a bridge between a data set and a data
source
SqlDataReader Provides a forward-only, read-only data stream of
the results
SqlError Holds information on SQL Server errors and
warnings
SqlException Defines the exception thrown on a SQL Server
error or warning
SqlParameter Represents a command parameter
SqlTransaction Represents a SQL Server transaction
OLE DB DATA PROVIDER
• A high performance data access technology still working.
• Used access data stored in any format.
• even it plays an important role in accessing data sources that
don’t have their own ADO.NET data providers.

Classes Description

OleDbCommand Executes SQL queries, statements, or stored


procedures
OleDbConnection Represents a connection to a OleDb data
source
OleDbDataAdapter Represents a bridge between a data set and a
data source
OleDbDataReader Provides a forward-only, read-only data
stream of rows from a data source
OleDbError Holds information on errors and warnings
returned by the data source
OleDbParameter Represents a command parameter
OleDbTransaction Represents a SQL transaction
• Ole DB providers

Provider Description

DB2OLEDB Microsoft OLE DB provider for DB2

SQLOLEDB Microsoft OLE DB provider for SQL Server

MicrosoftJet.OLEDB.4.0 Microsoft OLE DB provider for Access


(which uses the Jet engine)

MSDAORA Microsoft OLE DB provider for Oracle

MSDASQL Microsoft OLE DB provider for ODBC


ODBC DATA PROVIDER

• was Microsoft’s original general-purpose data access technology.


• still widely used for data sources that don’t have OLE DB providers
(.NET framework data providers)

• System.Data.Odbc is its namespace in ado.net


• Its architecture is essentially a three-tier process.
• The application:- uses odbc functions

• The Odbc :- converts function calls to protocols (call-level-interface)

• The driver:- communicates with the data source based on the odbc request.
• Pass the result or the error back to the odbc
• Less efficient than DB specific data providers.
• Some odbc classes
Classes Description

Executes SQL queries, statements, or stored


OdbcCommand procedures
OdbcConnection Represents a connection to an ODBC data
source
OdbcDataAdapter Represents a bridge between a data set and
a data source
OdbcDataReader Provides a forward-only, read-only data
stream of rows from a data source
OdbcError Holds information on errors and warnings
returned by the data source
OdbcParameter Represents a command parameter
OdbcTransaction Represents a SQL transaction
LINQ ARCHITECTURE

• Release with Visual Studio 2008 .NET Framework version 3.5


• that promises to revolutionize the way developers work with data.
• allows you to query various types of data sources
• relational databases
• XML documents
• and even in-memory data structures.
• LINQ offers the following advantages:

• common syntax for querying any type of data source


• bridges the gap and strengthens the connection between relational data and the object-
oriented world.

• LINQ speeds development time


• Query expressions are strongly typed
• LINQ consists of three major components:
• LINQ to Objects •
• LINQ to ADO.NET, which includes
• LINQ to SQL (formerly called DLinq)
• LINQ to DataSets (formerly called LINQ over DataSets)
• LINQ to Entities
• LINQ to XML (formerly called XLinq)
• Query expressions are written in a declarative query syntax.
• By using query syntax, you can perform filtering, ordering, and grouping operations on
data sources with a minimum of code.
THE END !

You might also like