SlideShare una empresa de Scribd logo
1 de 32
Made by:-
  Farzad
  Komal
 Aakash




            1
What is Ado.net?
 The full-form of ado.net is ActiveX Data Object.
 ADO.net is the 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.
 Ado.net is a collection of classes, interfaces, structures, enumerated type
that mange data access from the relational data stores
within the .net framework.




                                                                                2
ADO.NET
Understanding ADO.net   The Ado.net Object Model




                                                   3
Working with Ado.net
 Many of web application development ,in many of the developers
data situations involves opening data store, making request for
specific data, and then populating the table in then browser with the
data.
 To address the above situations Ado.net support the following
classes:
         1)DataSet
         2)DataReader




                                                                        4
Working with Ado.net namespaces
 The six core Ado.net namespaces are;
        1)System.Data
        2)System.Data.Common
        3)System.Data.OleDb
        4)System.Data.Odbc
        5)System.Data.SqlClient
        6)System.Data.SqlTypes




                                         5
 The classes from the above namespaces are categorized as follow:
 Disconnected : These Class provides basic structure of Ado.net includes
DataTable, etc. The object of this class are capable of storing data without
any dependency on specific data provide.
 Shared : Set of base classes for data provide and shared amount all data
provide. Includes DataSet, DataRow, DataTables, Constraint, etc.
 Data Provide : These classes are meant to work with different data
soures. Performs all database management operations a specific database.
 E.g. : SqlClient data provide works only with SQL Server Database.




                                                                               6
Type of Architecture
 ADO.NET is both Connection oriented as well as Disconnection oriented
* Connected : Forward-only, Read-only, mode.
        Application issues query then reads back results and processes them.
        DataReader object.
* Disconnected :
        Application issues query then retrieve and stores results for processing
        Minimizes time connected to database DataSet object.




                                                                              7
 Data Provider:- (Connected Environment)
A data provider is used for connecting to a database, retrieving data, storing the
data in a dataset, reading the retrieved data, and updating the database.
          * Connection:-This component is used to establish a connection with a
          data source such as database.
          * Command:-This component is used to retrieve, insert, delete, or modify
          data in a data source.
          * DataReader:-This component is used to retrieve data from a data
          source in a read-only and forward-only mode.
          * DataAdapter:-This component is used to transfer data to and from
          database. A datareader retrieve data from a database into a dataset.
 Data Set:- (Disconnected Environment)
The data set is a memory-based relational representation of data.
         * DataTableCollection:-It contains all table retrieved from the data source.
         * DataRelationCollection:-It contains relationship and links between table
         in a dataset.
         * DataTable:-It represent a table in the datatable collection of a dataset.
         * DataRowCollection:-It contains all the row in a datatable.
         * DataColoumnCollection:-It contains all the coloumn in a datatable.
                                                                                        8
ADO.NET Environment




                      9
Data isReader way of selecting
A data reader(SqlDataReader , etc.,) a simple and fastest
some data from a data source but also least capable.
       * You can't directly instantiate a data reader object. An instance is
       returned from appropriate Command object after having call
       ExecuteReader() method.
       * This data reader is forward-only , read-only connected cursor. You can
       only travels the records in one direction. Database connection used is kept
       open until the data reader has been closed.
       * The DataReader object requires a live connection to the database. So
       when you are done with DataReader object, be sure to call close(). If not
       connection stays alive.
       * When DataReader object is closed (via an explicit call to close) or the
       object being garbage collected, the underlying connection(con) may
       also be closed depending on which of the ExecuteReader() method is
       called.
       * If you call ExecuteReader() and pass CommandBehaviour.
                 CloseConnection you can force the connection to be closed when
the              reader is closed.                                             10
 For Data Reader object you have the following methods:
       * Read():Reads record by record in the data reader.
       * Close():Closes the SqlDataReader connection
       * Dispose():Disposes the data Reader object.
 Some of the important properties of Data Reader object are:
      * Connection: Gets the SqlConnection associated with the
                SqlDataReader.
      * HasRows : Gets the value that indicates whether the SqlDataReader
                contains one or more rows.
      * IsClosed: Retrieves a boolean value that indicates whether the
                specified SqlDataReader instance has been closed.




                                                                        11
Data Adapter
 The Data Adapter classes (Eg:SqlDataAdapter,..) bridges the gap between
the disconnected DataTable objects and the physical data source.
 The SqlDataAdapter provides two way data transfer mechanisms:
         * It is capable of executing SELECT statement on a data source and
         transferring the result set into a DataTable object.
         * It is also capable of executing the standard INSERT, UPDATE and
         DELETE statements and extracting the input data from DataTable
         object.




                                                                              12
 The commonly used properties of SqlDataAdapter class are:
        * Select Command: Gets or sets an object of type SqlCommand. This
        command is automatically executed to fill a Data Table with the result set.
        * Insert Command: Gets or sets an object of type SqlCommand.
        * Update Command: Gets or sets an object of type SqlCommand.
        * Delete Command: Gets or sets an object of type SqlCommand.
 This SqlDataAdapter class also provide a method called Fill().
        * Calling the Fill() method automatically execute the command provided by
        the Select Command property and retrieve the result set and copies it to
        DataTable.




                                                                                  13
Using Parameter
 If you requires SQL Statements that required you to configure using
parameters then you need to instantiate Parameter (i.e., SqlParameter,..,) object
and providing it with necessary information such as name, value, type, size,
direction , etc.,
 The following are properties of the SqlParameter class:-
         * ParameterName, SqlDbType, Size, Direction, SourceColoumn, value
 Coding Snipped in using parameters are:
         for e.g. : SqlCommand myCmd = new SqlCommand();
         myCmd.commandText = "SELECT * FROM CUSTOMERS WHERE
         CITY=@CITY";
         sqlParameter parmCity = new SqlParameter();
         parmCity.ParameterName="@CITY";
         parmCity.SqlDbType=SqlDbType.varchar;
         parmCity.Direction=ParameterDirection.input;
         parmCity.Value=“Ahmedabad“
         mycmd.Parameter.Add(parmCity);                                       14
DataSet
 The DataSet class has been designed as an offline container of data.
       * Data held within the DataSet is not necessary to come from
       database. It can be recorded from database. It can be recorded from
       CSV file, XML source, etc.
       * A DataSet class contains a set of Data Table classes and links
       between tables.
       for e.g. :
       foreach(DataRow row in ds.Tables["Customers"].rows);
       Console.WriteLine("{0} and {1}",row[0],row[1]);
 Each DataTable class consists DataColoumn, DataRow, Constraints and
  ExtendedProperties classes.
 .csv=Comma Separated Values


                                                                             15
 Here DataColoumn object defines the properties of a coloumn within
DataTable. These properties includes data type (Int32, Char, DateTime, etc.,),
read-only. You can also assign a name for coloumn.
         for e.g.:
         DataColoumn customerID=newDataColoumn("CustomerID",typeof
         (int));
         customerID.AllowDBNull=false;
         customerID.ReadOnly=false;
         customerID.AutoIncrement=true;
         customerID.Unique=true;
The actual data within a table is accessed via a DataRow object. One of the
interesting aspect of DataRow is that it is versioned. This permits you to
receive various values for a given coloumn in a particular row.




                                                                            16
DataSet




          17
DataSet Architecture
 You can create DataSet in any one of the following methods :
* Using Server Explorer
* Using DataAdapter
* Programmatically
* Using Xml




                                                                 18
 Coding snippet of using DataSet :
for e.g. :
       SqlConnection con = new SqlConnection(...);
       SqlCommand cmd = new SqlCommand(...);
       SqlDataAdapter da = new SqlDataAdapter (cmd, con);
       DataSet ds = new DataSet();
       da.Fill(ds, "MyTable");
 Better guideline regarding DataSet is :
       * Don't use DataSet object unless your project required to work with
       multiple DataTable object and you need a container for those object.
       * If you are working with single table then just use DataTable object
       rather then DataSet.
 You can create schemas for a DataTable in three ways.
         * Let the runtime do it for you.
         * Write code to create tables.
         * Use the XML schema generator.

                                                                           19
 The DataAdapter class is used to place the data in a DataSet class. This
Adapter class issues the SQL clause and fills a table within the DataSet.
         * for e.g. :
         SqlDataAdapter da = new SqlDataAdapter(strCmd , con);
         DataSet ds = new DataSet();
         da.Fill(ds, "Customers"); //Populating DataSet with DataAdapter.
 The DataSet class has been designed to establish relationships between
data tables with ease.
 At present you can apply the ForeignKeyConstraint and UniqueConstraint
on a columns in a DataSet.
 You can also set Update & Delete constraints on a columns that have
constraint relationships.




                                                                             20
 These rules are :
           * Cascade, None, Set Default, Set Null.
        for e.g. :
        DataTable dt = Get DataTable(); //It return DataTable
        DataColumn[] pk = new DataColumn[1];
        pk[0] = dt. Columns["StudentID"];
        dt.PrimaryKey = pk;
 The Constrains are enfored within a DataSet class if the
EnforcedConstraints property of the DataSet is true.




                                                                21
Data Providers Classes
 In .NET framework data provide is used for connecting to database,
executing commands are retrieving results. By default the following data
provides are included in .NET framework :
        * Data Provider for SQL Server
        * Data Provider for OLEDB
        * Data Provider for ODBC
        * Data Provider for Oracle
 In .NET to access the data set of classes defined in the namespaces
System.Data and other namespaces defined within this namespaces.




                                                                           22
 Each data provider contains the following objects:
 * Connection (for e.g. : Sqlconnection, Oracleconnection, Odbcconnection, etc.)
 * Command, CommandBuilder (for e.g. : Sqlconnection, SqlConnectionBuilder,
         etc.)
 * DataAdapter (for e.g. : SqlDataAdapter, etc.)
 * DataReader (for e.g. : SqlDataReader, etc)
 * Parameter (for e.g. : SqlParameter, etc)
 * Transaction (e.g. : SqlTransaction, etc)
 Each Provider use different namespaces. Their namespaces are in
respective :
         * System.Data.SqlClient
         * System.Data.Oledb
         * System.Data.Odbc
         * System.Data.OracleClient


                                                                             23
 In addition to above namespaces few more important namespaces in
ADO.NET are:
        * System.Data
        * System.Data.Comman
        * System.Data.SqlTypes
 ADO.NET consists number of classes that are used regardless you are
using the SQL Server Classes or OLEDB classes.
 The System.Data namespaces consists the following classes:
        * DataSet
        * DataTables
        * DataRow
        * DataColumn
        * DataRelation
        * Consraint



                                                                        24
Classes in Data Providers
 Each data provider supports the fallowing types of core objects to
communicate with database.
 The Connection object provides connectivity to a data source.
 The Command object enable access to database commands to return
data, modify data, run stored procedures, and send or retrieve parameter
information.
 The DataReader provides a high performance stream of the data from
the data source.
 Finally, the DataAdapter provides the bridge between the DataSet object
and the data source.
 The DataAdapter uses Command objects to execute SQL commands at
the data source to both load the DataSet with data, and renconcile change
made to the data in the data in the DataSet back to the data source.

                                                                            25
Connection Object
 The different Connection classes are in different data provider models.
          * for e.g. : SqlConnection, OleDbConnection, OracleConnection, etc.
 The properties of SqlConnection class are:
          * ConnectionString, DataSource, Database,State.
          * In above properties DataSource, Database, State are read-only mode.
 You can pass necessary connection string information to the SqlConnection
in a string format or store in "web.config" file.




                                                                              26
 You can store database connection parameters in configuration file under
<ConnectionString> section. Here you can specify name of connection,
connection string parameter and provider for this connection.
        * for e.g. usage of SqlConnection:
        SqlConnection con = new SqlConnection("Data
        Source=FARZADFWADIA-PC;Initial Catalog=FarzadWadia;
        Integrated Security=True");
        con.Open();//Use connection object.
        con.Close(); //you need to call this explicitly, because .net doesn't
                     implicitly release the connection when they fall out of scope.




                                                                              27
Command Object
 In Ado.net a command is a string of the containing SQL statements that is
to be issued to the database. It can also be a stored procedure or the name of
the table which return all columns and rows.
 A Command can be constructed by using the instance of SqlCommand.
         for e.g. :
         SqlCommand cmd = new SqlCommand("Select * from
         Employee",con);
 After building the command object you need to execute with any one of the
methods:
* ExecuteNonQuery() : Executes the command but doesn't return any output.
         Only it will return no of rows effected.
* ExecuteReader() : Executes the command and returns a type SqlDataReader.
* ExecuteRow() : Executes the command and returns SqlRecord, (Single row)
* ExecuteScalar() : Executes the command and returns a single values.
* ExecuteXmlReader() : Executes the command and returns XmlReader.

                                                                            28
 Some of the important properties of Command object are :
       * CommandText : Assign SQL statement or stored procedure name,
       * CommandTimeout : Specifies no of second to wait for executing a
       command
       * CommandType : Possible values are Text, Stored Procedure, Table direct.
       * Connection : Gets or Sets SqlConnection object.
 Calling a stored procedure with a Command object
       for e.g. :
       SqlCommand cmd = new SqlCommand("MyStoredProc“ , con);
       cmd.CommandType = CommandType,StoredProcedure;
       cmd.Parameter.Add(new SqlParameter(...));
       cmd.Paramter[0].Value = val;
       cmd.ExecuteNonQuery();




                                                                            29
ADO.NET Programming
 ADO.NET Programming involves the following steps:
       * Create a Connection object and provide connection string
       Information.
       * Create a Command object and provide details of SQL command
       that is to be executed.
       * Command can be inline SQL Text command, Stored Procedure
       or direct table access. Also provide required parameters if needed.
       * If your command doesn't return result set then execute the
       command simply by calling one of Execute method on Command
       object.
       * If your command object returns a result set then you can store
       the result set in DataReader or DataAdapter object.
       * To load the data from DataReader to DataTable just call Load()
       method on DataTable.
       SqlDataReader myReader=cmd.ExecuteReader(…);
       DataTable myTable=new DataTable();
       myTable.Load(myReader);                                               30
* In reverse if you want a reader from DataTable then use:
DataTableReader myReader=myTable.CreateDataReader();
* If you want to retain the result set for feature use without
maintaining the connection to the database then use DataAdapter
object. This DataAdapter object is used to fill DataSet or
DataTable objects.
* If you don't want to retain the result set, rather simply process
the command in a swift fashion, you use Command object needs a
live connection to database and it works as forward-only read-only
cursor.




                                                                  31
Student Name            StudentID
Farzad                  S111126900191
Komal                   S111126900185
Aakash                  S111126900166




                                             32

Más contenido relacionado

La actualidad más candente (20)

Ado.net
Ado.netAdo.net
Ado.net
 
Introduction To Dotnet
Introduction To DotnetIntroduction To Dotnet
Introduction To Dotnet
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
 
C# Basics
C# BasicsC# Basics
C# Basics
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
 
Introduction to .NET Framework
Introduction to .NET FrameworkIntroduction to .NET Framework
Introduction to .NET Framework
 
Ado.net
Ado.netAdo.net
Ado.net
 
ASP.NET Basics
ASP.NET Basics ASP.NET Basics
ASP.NET Basics
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
Ajax and Jquery
Ajax and JqueryAjax and Jquery
Ajax and Jquery
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Architecture of .net framework
Architecture of .net frameworkArchitecture of .net framework
Architecture of .net framework
 
OODM-object oriented data model
OODM-object oriented data modelOODM-object oriented data model
OODM-object oriented data model
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management System
 
database
databasedatabase
database
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Servlets
ServletsServlets
Servlets
 

Similar a ADO.NET Data Access Explained

Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net ArchitectureUmar Farooq
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to adoHarman Bajwa
 
LECTURE 14 Data Access.pptx
LECTURE 14 Data Access.pptxLECTURE 14 Data Access.pptx
LECTURE 14 Data Access.pptxAOmaAli
 
Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.Alexey Furmanov
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentalsMadhuri Kavade
 
Marmagna desai
Marmagna desaiMarmagna desai
Marmagna desaijmsthakur
 
Ado.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworksAdo.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworksLuis Goldster
 
ASP.NET Session 11 12
ASP.NET Session 11 12ASP.NET Session 11 12
ASP.NET Session 11 12Sisir Ghosh
 
Csharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptxCsharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptxfacebookrecovery1
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETEverywhere
 

Similar a ADO.NET Data Access Explained (20)

Ado.net
Ado.netAdo.net
Ado.net
 
Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net Architecture
 
Chap14 ado.net
Chap14 ado.netChap14 ado.net
Chap14 ado.net
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to ado
 
Ado
AdoAdo
Ado
 
LECTURE 14 Data Access.pptx
LECTURE 14 Data Access.pptxLECTURE 14 Data Access.pptx
LECTURE 14 Data Access.pptx
 
Ado.net
Ado.netAdo.net
Ado.net
 
Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.
 
ADO.NET by ASP.NET Development Company in india
ADO.NET by ASP.NET  Development Company in indiaADO.NET by ASP.NET  Development Company in india
ADO.NET by ASP.NET Development Company in india
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentals
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
 
Marmagna desai
Marmagna desaiMarmagna desai
Marmagna desai
 
Ado.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworksAdo.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworks
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
ASP.NET Session 11 12
ASP.NET Session 11 12ASP.NET Session 11 12
ASP.NET Session 11 12
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
 
Unit4
Unit4Unit4
Unit4
 
Ado .net
Ado .netAdo .net
Ado .net
 
Csharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptxCsharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptx
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NET
 

Último

Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Celine George
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17Celine George
 

Último (20)

Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17
 

ADO.NET Data Access Explained

  • 1. Made by:- Farzad Komal Aakash 1
  • 2. What is Ado.net?  The full-form of ado.net is ActiveX Data Object.  ADO.net is the 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.  Ado.net is a collection of classes, interfaces, structures, enumerated type that mange data access from the relational data stores within the .net framework. 2
  • 3. ADO.NET Understanding ADO.net The Ado.net Object Model 3
  • 4. Working with Ado.net  Many of web application development ,in many of the developers data situations involves opening data store, making request for specific data, and then populating the table in then browser with the data.  To address the above situations Ado.net support the following classes: 1)DataSet 2)DataReader 4
  • 5. Working with Ado.net namespaces  The six core Ado.net namespaces are; 1)System.Data 2)System.Data.Common 3)System.Data.OleDb 4)System.Data.Odbc 5)System.Data.SqlClient 6)System.Data.SqlTypes 5
  • 6.  The classes from the above namespaces are categorized as follow:  Disconnected : These Class provides basic structure of Ado.net includes DataTable, etc. The object of this class are capable of storing data without any dependency on specific data provide.  Shared : Set of base classes for data provide and shared amount all data provide. Includes DataSet, DataRow, DataTables, Constraint, etc.  Data Provide : These classes are meant to work with different data soures. Performs all database management operations a specific database.  E.g. : SqlClient data provide works only with SQL Server Database. 6
  • 7. Type of Architecture  ADO.NET is both Connection oriented as well as Disconnection oriented * Connected : Forward-only, Read-only, mode. Application issues query then reads back results and processes them. DataReader object. * Disconnected : Application issues query then retrieve and stores results for processing Minimizes time connected to database DataSet object. 7
  • 8.  Data Provider:- (Connected Environment) A data provider is used for connecting to a database, retrieving data, storing the data in a dataset, reading the retrieved data, and updating the database. * Connection:-This component is used to establish a connection with a data source such as database. * Command:-This component is used to retrieve, insert, delete, or modify data in a data source. * DataReader:-This component is used to retrieve data from a data source in a read-only and forward-only mode. * DataAdapter:-This component is used to transfer data to and from database. A datareader retrieve data from a database into a dataset.  Data Set:- (Disconnected Environment) The data set is a memory-based relational representation of data. * DataTableCollection:-It contains all table retrieved from the data source. * DataRelationCollection:-It contains relationship and links between table in a dataset. * DataTable:-It represent a table in the datatable collection of a dataset. * DataRowCollection:-It contains all the row in a datatable. * DataColoumnCollection:-It contains all the coloumn in a datatable. 8
  • 10. Data isReader way of selecting A data reader(SqlDataReader , etc.,) a simple and fastest some data from a data source but also least capable. * You can't directly instantiate a data reader object. An instance is returned from appropriate Command object after having call ExecuteReader() method. * This data reader is forward-only , read-only connected cursor. You can only travels the records in one direction. Database connection used is kept open until the data reader has been closed. * The DataReader object requires a live connection to the database. So when you are done with DataReader object, be sure to call close(). If not connection stays alive. * When DataReader object is closed (via an explicit call to close) or the object being garbage collected, the underlying connection(con) may also be closed depending on which of the ExecuteReader() method is called. * If you call ExecuteReader() and pass CommandBehaviour. CloseConnection you can force the connection to be closed when the reader is closed. 10
  • 11.  For Data Reader object you have the following methods: * Read():Reads record by record in the data reader. * Close():Closes the SqlDataReader connection * Dispose():Disposes the data Reader object.  Some of the important properties of Data Reader object are: * Connection: Gets the SqlConnection associated with the SqlDataReader. * HasRows : Gets the value that indicates whether the SqlDataReader contains one or more rows. * IsClosed: Retrieves a boolean value that indicates whether the specified SqlDataReader instance has been closed. 11
  • 12. Data Adapter  The Data Adapter classes (Eg:SqlDataAdapter,..) bridges the gap between the disconnected DataTable objects and the physical data source.  The SqlDataAdapter provides two way data transfer mechanisms: * It is capable of executing SELECT statement on a data source and transferring the result set into a DataTable object. * It is also capable of executing the standard INSERT, UPDATE and DELETE statements and extracting the input data from DataTable object. 12
  • 13.  The commonly used properties of SqlDataAdapter class are: * Select Command: Gets or sets an object of type SqlCommand. This command is automatically executed to fill a Data Table with the result set. * Insert Command: Gets or sets an object of type SqlCommand. * Update Command: Gets or sets an object of type SqlCommand. * Delete Command: Gets or sets an object of type SqlCommand.  This SqlDataAdapter class also provide a method called Fill(). * Calling the Fill() method automatically execute the command provided by the Select Command property and retrieve the result set and copies it to DataTable. 13
  • 14. Using Parameter  If you requires SQL Statements that required you to configure using parameters then you need to instantiate Parameter (i.e., SqlParameter,..,) object and providing it with necessary information such as name, value, type, size, direction , etc.,  The following are properties of the SqlParameter class:- * ParameterName, SqlDbType, Size, Direction, SourceColoumn, value  Coding Snipped in using parameters are: for e.g. : SqlCommand myCmd = new SqlCommand(); myCmd.commandText = "SELECT * FROM CUSTOMERS WHERE CITY=@CITY"; sqlParameter parmCity = new SqlParameter(); parmCity.ParameterName="@CITY"; parmCity.SqlDbType=SqlDbType.varchar; parmCity.Direction=ParameterDirection.input; parmCity.Value=“Ahmedabad“ mycmd.Parameter.Add(parmCity); 14
  • 15. DataSet  The DataSet class has been designed as an offline container of data. * Data held within the DataSet is not necessary to come from database. It can be recorded from database. It can be recorded from CSV file, XML source, etc. * A DataSet class contains a set of Data Table classes and links between tables. for e.g. : foreach(DataRow row in ds.Tables["Customers"].rows); Console.WriteLine("{0} and {1}",row[0],row[1]);  Each DataTable class consists DataColoumn, DataRow, Constraints and ExtendedProperties classes.  .csv=Comma Separated Values 15
  • 16.  Here DataColoumn object defines the properties of a coloumn within DataTable. These properties includes data type (Int32, Char, DateTime, etc.,), read-only. You can also assign a name for coloumn. for e.g.: DataColoumn customerID=newDataColoumn("CustomerID",typeof (int)); customerID.AllowDBNull=false; customerID.ReadOnly=false; customerID.AutoIncrement=true; customerID.Unique=true; The actual data within a table is accessed via a DataRow object. One of the interesting aspect of DataRow is that it is versioned. This permits you to receive various values for a given coloumn in a particular row. 16
  • 17. DataSet 17
  • 18. DataSet Architecture  You can create DataSet in any one of the following methods : * Using Server Explorer * Using DataAdapter * Programmatically * Using Xml 18
  • 19.  Coding snippet of using DataSet : for e.g. : SqlConnection con = new SqlConnection(...); SqlCommand cmd = new SqlCommand(...); SqlDataAdapter da = new SqlDataAdapter (cmd, con); DataSet ds = new DataSet(); da.Fill(ds, "MyTable");  Better guideline regarding DataSet is : * Don't use DataSet object unless your project required to work with multiple DataTable object and you need a container for those object. * If you are working with single table then just use DataTable object rather then DataSet.  You can create schemas for a DataTable in three ways. * Let the runtime do it for you. * Write code to create tables. * Use the XML schema generator. 19
  • 20.  The DataAdapter class is used to place the data in a DataSet class. This Adapter class issues the SQL clause and fills a table within the DataSet. * for e.g. : SqlDataAdapter da = new SqlDataAdapter(strCmd , con); DataSet ds = new DataSet(); da.Fill(ds, "Customers"); //Populating DataSet with DataAdapter.  The DataSet class has been designed to establish relationships between data tables with ease.  At present you can apply the ForeignKeyConstraint and UniqueConstraint on a columns in a DataSet.  You can also set Update & Delete constraints on a columns that have constraint relationships. 20
  • 21.  These rules are : * Cascade, None, Set Default, Set Null. for e.g. : DataTable dt = Get DataTable(); //It return DataTable DataColumn[] pk = new DataColumn[1]; pk[0] = dt. Columns["StudentID"]; dt.PrimaryKey = pk;  The Constrains are enfored within a DataSet class if the EnforcedConstraints property of the DataSet is true. 21
  • 22. Data Providers Classes  In .NET framework data provide is used for connecting to database, executing commands are retrieving results. By default the following data provides are included in .NET framework : * Data Provider for SQL Server * Data Provider for OLEDB * Data Provider for ODBC * Data Provider for Oracle  In .NET to access the data set of classes defined in the namespaces System.Data and other namespaces defined within this namespaces. 22
  • 23.  Each data provider contains the following objects: * Connection (for e.g. : Sqlconnection, Oracleconnection, Odbcconnection, etc.) * Command, CommandBuilder (for e.g. : Sqlconnection, SqlConnectionBuilder, etc.) * DataAdapter (for e.g. : SqlDataAdapter, etc.) * DataReader (for e.g. : SqlDataReader, etc) * Parameter (for e.g. : SqlParameter, etc) * Transaction (e.g. : SqlTransaction, etc)  Each Provider use different namespaces. Their namespaces are in respective : * System.Data.SqlClient * System.Data.Oledb * System.Data.Odbc * System.Data.OracleClient 23
  • 24.  In addition to above namespaces few more important namespaces in ADO.NET are: * System.Data * System.Data.Comman * System.Data.SqlTypes  ADO.NET consists number of classes that are used regardless you are using the SQL Server Classes or OLEDB classes.  The System.Data namespaces consists the following classes: * DataSet * DataTables * DataRow * DataColumn * DataRelation * Consraint 24
  • 25. Classes in Data Providers  Each data provider supports the fallowing types of core objects to communicate with database.  The Connection object provides connectivity to a data source.  The Command object enable access to database commands to return data, modify data, run stored procedures, and send or retrieve parameter information.  The DataReader provides a high performance stream of the data from the data source.  Finally, the DataAdapter provides the bridge between the DataSet object and the data source.  The DataAdapter uses Command objects to execute SQL commands at the data source to both load the DataSet with data, and renconcile change made to the data in the data in the DataSet back to the data source. 25
  • 26. Connection Object  The different Connection classes are in different data provider models. * for e.g. : SqlConnection, OleDbConnection, OracleConnection, etc.  The properties of SqlConnection class are: * ConnectionString, DataSource, Database,State. * In above properties DataSource, Database, State are read-only mode.  You can pass necessary connection string information to the SqlConnection in a string format or store in "web.config" file. 26
  • 27.  You can store database connection parameters in configuration file under <ConnectionString> section. Here you can specify name of connection, connection string parameter and provider for this connection. * for e.g. usage of SqlConnection: SqlConnection con = new SqlConnection("Data Source=FARZADFWADIA-PC;Initial Catalog=FarzadWadia; Integrated Security=True"); con.Open();//Use connection object. con.Close(); //you need to call this explicitly, because .net doesn't implicitly release the connection when they fall out of scope. 27
  • 28. Command Object  In Ado.net a command is a string of the containing SQL statements that is to be issued to the database. It can also be a stored procedure or the name of the table which return all columns and rows.  A Command can be constructed by using the instance of SqlCommand. for e.g. : SqlCommand cmd = new SqlCommand("Select * from Employee",con);  After building the command object you need to execute with any one of the methods: * ExecuteNonQuery() : Executes the command but doesn't return any output. Only it will return no of rows effected. * ExecuteReader() : Executes the command and returns a type SqlDataReader. * ExecuteRow() : Executes the command and returns SqlRecord, (Single row) * ExecuteScalar() : Executes the command and returns a single values. * ExecuteXmlReader() : Executes the command and returns XmlReader. 28
  • 29.  Some of the important properties of Command object are : * CommandText : Assign SQL statement or stored procedure name, * CommandTimeout : Specifies no of second to wait for executing a command * CommandType : Possible values are Text, Stored Procedure, Table direct. * Connection : Gets or Sets SqlConnection object.  Calling a stored procedure with a Command object for e.g. : SqlCommand cmd = new SqlCommand("MyStoredProc“ , con); cmd.CommandType = CommandType,StoredProcedure; cmd.Parameter.Add(new SqlParameter(...)); cmd.Paramter[0].Value = val; cmd.ExecuteNonQuery(); 29
  • 30. ADO.NET Programming  ADO.NET Programming involves the following steps: * Create a Connection object and provide connection string Information. * Create a Command object and provide details of SQL command that is to be executed. * Command can be inline SQL Text command, Stored Procedure or direct table access. Also provide required parameters if needed. * If your command doesn't return result set then execute the command simply by calling one of Execute method on Command object. * If your command object returns a result set then you can store the result set in DataReader or DataAdapter object. * To load the data from DataReader to DataTable just call Load() method on DataTable. SqlDataReader myReader=cmd.ExecuteReader(…); DataTable myTable=new DataTable(); myTable.Load(myReader); 30
  • 31. * In reverse if you want a reader from DataTable then use: DataTableReader myReader=myTable.CreateDataReader(); * If you want to retain the result set for feature use without maintaining the connection to the database then use DataAdapter object. This DataAdapter object is used to fill DataSet or DataTable objects. * If you don't want to retain the result set, rather simply process the command in a swift fashion, you use Command object needs a live connection to database and it works as forward-only read-only cursor. 31
  • 32. Student Name StudentID Farzad S111126900191 Komal S111126900185 Aakash S111126900166 32