overview of ado.net by software outsourcing company india

14
iFour Consultancy Introduction to ADO.Net

Upload: jignesh-aakoliya

Post on 20-Jan-2017

42 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Overview of ADO.net by software outsourcing company india

iFour Consultancy

Introduction to ADO.Net

Page 2: Overview of ADO.net by software outsourcing company india

Introduction to ADO.Net : Definition

• ADO.NET is an object-oriented set of libraries that allows you to communicate with data sources. Commonly, the data source is a database, but it could also be a text file, an Excel spreadsheet, or an XML file. It has classes and methods to retrieve and manipulate data.

• ADO.NET provides a bridge between the front end controls and the back end database. The ADO.NET objects encapsulate all the data access operations and the controls communicate with these objects to display data, thus hiding the details of movement of data.

•A markup language is a set of markup tags

Software Outsourcing Company Indiahttp://www.ifourtechnolab.com

Page 3: Overview of ADO.net by software outsourcing company india

Introduction to ADO.Net : Data Providers ADO.NET provides a relatively common way to communicate with data sources, but comes in different sets of libraries for each way you can talk to a data source. These libraries are called Data Providers and are usually named for the protocol or data source type they allow you to communicate with. Table below lists some well known data providers, the API prefix they use, and the type of data source they allow you to communicate with.

Provider Name API prefix Data Source DescriptionODBC Data Provider Odbc Data Sources with an ODBC interface. Normally older data bases.OleDb Data Provider OleDb Data Sources that expose an OleDb interface, i.e. Access or Excel.Oracle Data Provider Oracle For Oracle Databases.SQL Data Provider Sql For interacting with Microsoft SQL Server.Borland Data Provider Bdp Generic access to many databases such as Interbase, SQL Server, IBM DB2, and Oracle.

Software Outsourcing Company Indiahttp://www.ifourtechnolab.com

Page 4: Overview of ADO.net by software outsourcing company india

SqlConnection Class SqlCommand ClassSqlDataReader ClassSqlDataAdaptor ClassDataSet Class

Introduction to ADO.Net : Classes

Software Outsourcing Company Indiahttp://www.ifourtechnolab.com

Page 5: Overview of ADO.net by software outsourcing company india

To communicate with a database, you must have a connection to it. The connection helps identify the database server, the database name, user name, password, and other parameters that are required for connecting to the data base.

A connection class object is used by command objects so they will know which database to execute the command on.

Introduction to ADO.Net : SqlConnection Class

Software Outsourcing Company Indiahttp://www.ifourtechnolab.com

Page 6: Overview of ADO.net by software outsourcing company india

The process of communicating with a database means that you must specify the actions you want to occur. This is done with a command object. You use a command object to send SQL statements to the database. A command object uses a connection object to figure out which database to communicate with. You can use a command object alone, to execute a command directly, or assign a reference to a command object to an SqlDataAdapter, which holds a set of commands that work on a group of data as described below.

The Command class provides methods for storing and executing SQL statements and Stored Procedures. The following are the various commands that are executed by the Command Class. ExecuteReader: Returns data to the client as rows. This would typically be an SQL select statement or a Stored Procedure that contains

one or more select statements. This method returns a DataReader object that can be used to fill a DataTable object or used directly for printing reports and so forth.

ExecuteNonQuery: Executes a command that changes the data in the database, such as an update, delete, or insert statement, or a Stored Procedure that contains one or more of these statements. This method returns an integer that is the number of rows affected by the query.

ExecuteScalar: This method only returns a single value. This kind of query returns a count of rows or a calculated value. ExecuteXMLReader: (SqlClient classes only) Obtains data from an SQL Server 2000 database using an XML stream. Returns an XML

Reader object.

Introduction to ADO.Net : SqlCommand Class

Software Outsourcing Company India

Page 7: Overview of ADO.net by software outsourcing company india

• Many data operations require that you only get a stream of data for reading. The data reader object allows you to obtain the results of a SELECT statement from a command object.

• For performance reasons, the data returned from a data reader is a fast forward-only stream of data. This means that you can only pull the data from the stream in a sequential manner This is good for speed, but if you need to manipulate data, then a DataSet is a better object to work with.

Introduction to ADO.Net : SqlDataReader Class

Software Outsourcing Company Indiahttp://www.ifourtechnolab.com

Page 8: Overview of ADO.net by software outsourcing company india

Sometimes the data you work with is primarily read-only and you rarely need to make changes to the underlying data source Some situations also call for caching data in memory to minimize the number of database calls for data that does not change.

The data adapter makes it easy for you to accomplish these things by helping to manage data in a disconnected mode. The data adapter fills a DataSet object when reading the data and writes in a single batch when persisting changes back to the database.

A data adapter contains a reference to the connection object and opens and closes the connection automatically when reading from or writing to the database. Additionally, the data adapter contains command object references for SELECT, INSERT, UPDATE, and DELETE operations on the data.

You will have a data adapter defined for each table in a DataSet and it will take care of all communication with the database for you. All you need to do is tell the data adapter when to load from or write to the database.

Introduction to ADO.Net : SqlDataAdaptor Class

Software Outsourcing Company Indiahttp://www.ifourtechnolab.com

Page 9: Overview of ADO.net by software outsourcing company india

DataSet objects are in-memory representations of data. They contain multiple Datatable objects, which contain columns and rows, just like normal database tables. You can even define relations between tables to create parent-child relationships.

The DataSet is specifically designed to help manage data in memory and to support disconnected operations on data, when such a scenario make sense.

The DataSet is an object that is used by all of the Data Providers, which is why it does not have a Data Provider specific prefix.

Introduction to ADO.Net : DataSet Class

Software Outsourcing Company Indiahttp://www.ifourtechnolab.com

Page 10: Overview of ADO.net by software outsourcing company india

The architecture of ADO.net, in which connection must be opened to access the data retrieved from database is called as connected architecture. Connected architecture was built on the classes connection, command, datareader and transaction.

Connected architecture is when you constantly make trips to the database for any CRUD (Create, Read, Update and Delete) operation you wish to do. This creates more traffic to the database but is normally much faster as you should be doing smaller transactions.

Example:

Introduction to ADO.Net : Connected architecture

Database

Web Form

Software Outsourcing Company Indiahttp://www.ifourtechnolab.com

Page 11: Overview of ADO.net by software outsourcing company india

The architecture of ADO.net in which data retrieved from database can be accessed even when connection to database was closed is called as disconnected architecture. Disconnected architecture of ADO.net was built on classes connection, dataadapter, commandbuilder and dataset and dataview.

Disconnected architecture is a method of retrieving a record set from the database and storing it giving you the ability to do many CRUD (Create, Read, Update and Delete) operations on the data in memory, then it can be re-synchronized with the database when reconnecting. A method of using disconnected architecture is using a Dataset.

Example:

Introduction to ADO.Net : Disconnected architecture

Database

Web Form

Data Adapter

Software Outsourcing Company Indiahttp://www.ifourtechnolab.com

Page 12: Overview of ADO.net by software outsourcing company india

A layer is a reusable portion of code that performs a specific function. In the .NET environment, a layer is usually set up as a project that represents this specific function. This specific layer is in charge of working with other layers to perform some specific goal.

Data Layer - A DAL contains methods that helps the Business Layer to connect the data and perform required actions, whether to return data or to manipulate data (insert, update, delete and so on).

Business Layer - A BAL contains business logic, validations or calculations related to the data. Though a web site could talk to the data access layer directly, it usually goes through another layer called the Business Layer. The Business Layer is vital in that it validates the input conditions before calling a method from the data layer. This ensures the data input is correct before proceeding, and can often ensure that the outputs are correct as well. This validation of input is called business rules, meaning the rules that the Business Layer uses to make “judgments” about the data.

Presentation Layer - The Presentation Layer contains pages like .aspx or Windows Forms where data is presented to the user or input is taken from the user. The ASP.NET web site or Windows Forms application (the UI for the project) is called the Presentation Layer. The Presentation Layer is the most important layer simply because it’s the one that everyone sees and uses. Even with a well structured business and data layer, if the Presentation Layer is designed poorly, this gives the users a poor view of the system.

Introduction to ADO.Net : 3-Tier Architecture

Software Outsourcing Company Indiahttp://www.ifourtechnolab.com

Page 13: Overview of ADO.net by software outsourcing company india

Graphical representation of 3-Tier Architecture

Introduction to ADO.Net : 3-Tier Architecture Example

UIAsp.net

MVC

Eg:a=20;B=10;

Store c;

BLLC#.net

Eg:c=a+b;

DALAdo.Net

Eg:Ouput

c;

DataBaseEg: Ms Sqlserver

Presentation Layer also called User

Interface. Computer, Mobile phone..etc.

Business Logic LayerDoes all the logic

operations

Data Access LayerCommunicate with

the database

Software Outsourcing Company Indiahttp://www.ifourtechnolab.com

Page 14: Overview of ADO.net by software outsourcing company india

Thank you

Software development company indiahttp://www.ifourtechnolab.com