SlideShare a Scribd company logo
LECTURE 6
ADO.NET Overview
What is ADO.NET
• ADO.NET (Active Data Objects) is the data access
component of the .NET Framework
• Used to develop data bound Windows Forms and Web Forms
• Like other components of the .NET Framework,
ADO.NET consists of a set of classes that
interact to provide the required functionality
• VS 2008 (and greater) and .NET 2.0 (and greater) make
development much easier
• ADO.NET classes are divided to two primary components
• Data Providers handle communication with the data source
• Data Sets represent the actual data from the data source
ADO.NET Object Model
• The primary objects in the ADO.NET object model
• The true reality of the class library is
considerably more complicated
Data Providers
• Data Provider components are specific to a data
source
• A generic provider that can communicate
with any OLE DB data source (Access etc)
• An SQL Server provider, optimized
for SQL Server 7, 2000 & 2005
• An ODBC provider that can communicate
with an ODBC data source (MySQL etc)
• An Oracle provider, optimized for access to Oracle
• Data Providers contain the same objects
• SqlConnection, OleDbConnection, OracleConnection etc
SqlConnection
The SqlConnection class is used to establish a
connection to a SQL Server database. The SqlConnection
class is used for opening connections, setting or
retrieving properties of a connection, or handling
connection-related events.
Connection objects represent the physical connections
to data sources
• Their properties determine the data provider,
the data source, the database to connect to
and the string to be used during connection
– Their methods are fairly simple. You can open
and close the connection, change the database
and manage transactions
SqlCommand
The SqlCommand class is used to execute SQL statements
or stored procedures against a SQL Server database. The
SqlCommand class can execute statements or stored
procedures that do not return values, or that return
single values, XML, or datareaders.
• Command objects can be executed against a connection
They are also used by DataAdapter objects to handle the
communication requirements of DataSet objects.
SqlDataReader
The SqlDataReader class provides forward-only, read-
only only access to a set of rows returned from a SQL
Server database. Datareader provide high-performance
access to read-only data and is the
best choice for accessing data to be displayed in
ASP.NET.
• DataReader objects can not be created directly
in code as they are constructed by calling the
ExecuteReader method of a Command object
SqlDataAdapter
The SqlDataAdapter class is used as a bridge between the
DataSet class and SQL Server. You can use the
SqlDataAdapter class to create a dataset from a given
SQL statement or stored procedure represented by a
SqlCommand instance, to update the back-end SQL Server
database based on the contents of a dataset, or to
insert rows into or delete rows from a SQL Server
database.
• It provides an automated bridge between
a Connection object and a DataSet object
• A DataAdapter object contains four Command
objects, one each, for SELECT, UPDATE,
INSERT and DELETE based SQL statements
Sample 1
SqlConnection com;
SqlTransaction tran;
try {
con = new SqlConnection(connectionString);
con.open();
tran = con.BeginTransaction();
SqlCommand cmd = new SqlCommand(“DELETE FROM Customers”, con);
cmd.Transaction = tran;
cmd.ExecuteNonQuery();
}
catch (SqlException ex) {
if(tran!=null) tran.Rollback();
}
finally {
if(con!=null) con.Close();
}
Sample 2
SqlConnection com;
SqlTransaction tran;
try {
con = new SqlConnection(connectionString);
con.open();
SqlCommand cmd = new SqlCommand(“SELECT * FROM Customers”, con);
SqlDataReader rdr = cmd.ExecuteReader();
while(rdr.Read())
{
Console.WriteLine(rdr[0]);
}
}
catch (SqlException ex) {
if(tran!=null) tran.Rollback();
}
finally {
if(rdr!=null) rdr.Close(); if(con!=null) con.Close();
}
Data Sets
• The DataSet object is a memory resident copy of data
• The DataSet can be considered a somewhat simplified
relational database as it models tables and any
relationships between them
• The DataSet is always disconnected from the data source
• The DataSet is composed of two primary objects
• The DataTableCollection, accessed
through the Tables property
• The DataRelationCollection, accessed
through the Relations property
…cont
• The member or child objects in the DataSet object
Sample 3
SqlConnection com;
SqlTransaction tran;
try {
con = new SqlConnection(connectionString);
con.open();
SqlCommand cmd = new SqlCommand(“SELECT * FROM Customers”, con);
SqlDataReader rdr = cmd.ExecuteReader();
DataTable tbl = new DataTable(“MYTABLE1”);
tbl.Load(rdr);
dataGridView1.DataSource = tbl;
}
catch (SqlException ex) {
if(tran!=null) tran.Rollback();
}
finally {
if(rdr!=null) rdr.Close(); if(con!=null) con.Close();
}
GridView picture
Summary
• ADO.NET is the data access component of .NET
Framework
• Classes are split between Data Providers and Data Sets

More Related Content

What's hot (19)

PPTX
ADO.NET -database connection
Anekwong Yoddumnern
 
PPSX
ADO.NET
Farzad Wadia
 
PPT
ADO .Net
DrSonali Vyas
 
PPTX
Chapter 3: ado.net
Ngeam Soly
 
PPT
For Beginers - ADO.Net
Snehal Harawande
 
PPT
Ado.net
dina1985vlr
 
PPTX
ADO.NET by ASP.NET Development Company in india
iFour Institute - Sustainable Learning
 
PDF
Understanding C# in .NET
mentorrbuddy
 
PPT
ASP.NET 09 - ADO.NET
Randy Connolly
 
PPT
ASP.NET Session 11 12
Sisir Ghosh
 
PPSX
ASP.Net Presentation Part2
Neeraj Mathur
 
PPTX
Ch06 ado.net fundamentals
Madhuri Kavade
 
PPT
Marmagna desai
jmsthakur
 
PPT
ADO.net control
Paneliya Prince
 
PPT
Database programming in vb net
Zishan yousaf
 
PDF
Ado.net
Vikas Trivedi
 
PPS
VISUAL BASIC .net data accesss vii
argusacademy
 
PDF
Visual Basic.Net & Ado.Net
FaRid Adwa
 
ADO.NET -database connection
Anekwong Yoddumnern
 
ADO.NET
Farzad Wadia
 
ADO .Net
DrSonali Vyas
 
Chapter 3: ado.net
Ngeam Soly
 
For Beginers - ADO.Net
Snehal Harawande
 
Ado.net
dina1985vlr
 
ADO.NET by ASP.NET Development Company in india
iFour Institute - Sustainable Learning
 
Understanding C# in .NET
mentorrbuddy
 
ASP.NET 09 - ADO.NET
Randy Connolly
 
ASP.NET Session 11 12
Sisir Ghosh
 
ASP.Net Presentation Part2
Neeraj Mathur
 
Ch06 ado.net fundamentals
Madhuri Kavade
 
Marmagna desai
jmsthakur
 
ADO.net control
Paneliya Prince
 
Database programming in vb net
Zishan yousaf
 
Ado.net
Vikas Trivedi
 
VISUAL BASIC .net data accesss vii
argusacademy
 
Visual Basic.Net & Ado.Net
FaRid Adwa
 

Similar to Lecture 6. ADO.NET Overview. (20)

PPTX
Ado.net
pacatarpit
 
PPT
Ado
abhay singh
 
PPT
Chapter 4 event it theory programming.pptx
kmkkali41
 
PDF
Ado.Net Architecture
Umar Farooq
 
DOC
Ado
actacademy
 
PDF
Presentation on the ADO.NET framework in C#
kittu57736
 
PPT
the .NET Framework. It provides the claf
TesfahunMaru1
 
PPTX
111111112222223333335555555666Unit-4.pptx
sachaniajay26
 
PPTX
ADO architecture of XML andd Windows form
RamaSubramanian79
 
PDF
Unit4
Abha Damani
 
PPT
Introduction to ado
Harman Bajwa
 
PPTX
Csharp_dotnet_ADO_Net_database_query.pptx
facebookrecovery1
 
PPTX
LECTURE 14 Data Access.pptx
AOmaAli
 
PPTX
Latest Advance Animated Ado.Net With JDBC
Tarun Jain
 
PPTX
Ado.net
Om Prakash
 
PPTX
Is2215 lecture7 lecturer_ado_intro
dannygriff1
 
PPTX
PPT temp.pptx
Raghunathan52
 
PPTX
ADO .NET by Sonu Vishwakarma
Sonu Vishwakarma
 
DOCX
Ado dot net complete meterial (1)
Mubarak Hussain
 
PPTX
Asp .Net Database Connectivity Presentation.pptx
sridharu1981
 
Ado.net
pacatarpit
 
Chapter 4 event it theory programming.pptx
kmkkali41
 
Ado.Net Architecture
Umar Farooq
 
Presentation on the ADO.NET framework in C#
kittu57736
 
the .NET Framework. It provides the claf
TesfahunMaru1
 
111111112222223333335555555666Unit-4.pptx
sachaniajay26
 
ADO architecture of XML andd Windows form
RamaSubramanian79
 
Introduction to ado
Harman Bajwa
 
Csharp_dotnet_ADO_Net_database_query.pptx
facebookrecovery1
 
LECTURE 14 Data Access.pptx
AOmaAli
 
Latest Advance Animated Ado.Net With JDBC
Tarun Jain
 
Ado.net
Om Prakash
 
Is2215 lecture7 lecturer_ado_intro
dannygriff1
 
PPT temp.pptx
Raghunathan52
 
ADO .NET by Sonu Vishwakarma
Sonu Vishwakarma
 
Ado dot net complete meterial (1)
Mubarak Hussain
 
Asp .Net Database Connectivity Presentation.pptx
sridharu1981
 
Ad

More from Alexey Furmanov (12)

PPT
Лекция 9. Основы HTML. Часть 2.
Alexey Furmanov
 
PPT
Лекция 8. HTML основы. Часть 1.
Alexey Furmanov
 
PPT
Лекция 5. Поисковые системы.
Alexey Furmanov
 
PPT
Лекция 4. Почтовая система. Outlook.
Alexey Furmanov
 
PPT
Лекция 2. IP-адресация.
Alexey Furmanov
 
PPT
Лекция 3. Браузеры (2009)
Alexey Furmanov
 
PPT
Лекция 10. Основы CSS.
Alexey Furmanov
 
PPT
Лекция 1. Модель OSI.
Alexey Furmanov
 
PPT
Lecture 4. MS SQL. DML Triggers
Alexey Furmanov
 
PPT
Lecture 3. MS SQL. Cursors.
Alexey Furmanov
 
PPT
Lecture 2. MS SQL. Stored procedures.
Alexey Furmanov
 
ODP
Lecture 5. MS SQL. Transactions
Alexey Furmanov
 
Лекция 9. Основы HTML. Часть 2.
Alexey Furmanov
 
Лекция 8. HTML основы. Часть 1.
Alexey Furmanov
 
Лекция 5. Поисковые системы.
Alexey Furmanov
 
Лекция 4. Почтовая система. Outlook.
Alexey Furmanov
 
Лекция 2. IP-адресация.
Alexey Furmanov
 
Лекция 3. Браузеры (2009)
Alexey Furmanov
 
Лекция 10. Основы CSS.
Alexey Furmanov
 
Лекция 1. Модель OSI.
Alexey Furmanov
 
Lecture 4. MS SQL. DML Triggers
Alexey Furmanov
 
Lecture 3. MS SQL. Cursors.
Alexey Furmanov
 
Lecture 2. MS SQL. Stored procedures.
Alexey Furmanov
 
Lecture 5. MS SQL. Transactions
Alexey Furmanov
 
Ad

Recently uploaded (20)

PDF
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
SAMPLING: DEFINITION,PROCESS,TYPES,SAMPLE SIZE, SAMPLING ERROR.pptx
PRADEEP ABOTHU
 
PPTX
ANORECTAL MALFORMATIONS: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
PPTX
LEGAL ASPECTS OF PSYCHIATRUC NURSING.pptx
PoojaSen20
 
PPTX
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
 
PPT
digestive system for Pharm d I year HAP
rekhapositivity
 
PPTX
Gall bladder, Small intestine and Large intestine.pptx
rekhapositivity
 
PPTX
classroom based quiz bee.pptx...................
ferdinandsanbuenaven
 
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
PPTX
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
How to Manage Promotions in Odoo 18 Sales
Celine George
 
PPTX
Mrs Mhondiwa Introduction to Algebra class
sabinaschimanga
 
PPTX
Modern analytical techniques used to characterize organic compounds. Birbhum ...
AyanHossain
 
PPTX
Blanket Order in Odoo 17 Purchase App - Odoo Slides
Celine George
 
PPTX
CBSE to Conduct Class 10 Board Exams Twice a Year Starting 2026 .pptx
Schoolsof Dehradun
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PPTX
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
SAMPLING: DEFINITION,PROCESS,TYPES,SAMPLE SIZE, SAMPLING ERROR.pptx
PRADEEP ABOTHU
 
ANORECTAL MALFORMATIONS: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
LEGAL ASPECTS OF PSYCHIATRUC NURSING.pptx
PoojaSen20
 
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
 
digestive system for Pharm d I year HAP
rekhapositivity
 
Gall bladder, Small intestine and Large intestine.pptx
rekhapositivity
 
classroom based quiz bee.pptx...................
ferdinandsanbuenaven
 
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
How to Manage Promotions in Odoo 18 Sales
Celine George
 
Mrs Mhondiwa Introduction to Algebra class
sabinaschimanga
 
Modern analytical techniques used to characterize organic compounds. Birbhum ...
AyanHossain
 
Blanket Order in Odoo 17 Purchase App - Odoo Slides
Celine George
 
CBSE to Conduct Class 10 Board Exams Twice a Year Starting 2026 .pptx
Schoolsof Dehradun
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 

Lecture 6. ADO.NET Overview.

  • 2. What is ADO.NET • ADO.NET (Active Data Objects) is the data access component of the .NET Framework • Used to develop data bound Windows Forms and Web Forms • Like other components of the .NET Framework, ADO.NET consists of a set of classes that interact to provide the required functionality • VS 2008 (and greater) and .NET 2.0 (and greater) make development much easier • ADO.NET classes are divided to two primary components • Data Providers handle communication with the data source • Data Sets represent the actual data from the data source
  • 3. ADO.NET Object Model • The primary objects in the ADO.NET object model • The true reality of the class library is considerably more complicated
  • 4. Data Providers • Data Provider components are specific to a data source • A generic provider that can communicate with any OLE DB data source (Access etc) • An SQL Server provider, optimized for SQL Server 7, 2000 & 2005 • An ODBC provider that can communicate with an ODBC data source (MySQL etc) • An Oracle provider, optimized for access to Oracle • Data Providers contain the same objects • SqlConnection, OleDbConnection, OracleConnection etc
  • 5. SqlConnection The SqlConnection class is used to establish a connection to a SQL Server database. The SqlConnection class is used for opening connections, setting or retrieving properties of a connection, or handling connection-related events. Connection objects represent the physical connections to data sources • Their properties determine the data provider, the data source, the database to connect to and the string to be used during connection – Their methods are fairly simple. You can open and close the connection, change the database and manage transactions
  • 6. SqlCommand The SqlCommand class is used to execute SQL statements or stored procedures against a SQL Server database. The SqlCommand class can execute statements or stored procedures that do not return values, or that return single values, XML, or datareaders. • Command objects can be executed against a connection They are also used by DataAdapter objects to handle the communication requirements of DataSet objects.
  • 7. SqlDataReader The SqlDataReader class provides forward-only, read- only only access to a set of rows returned from a SQL Server database. Datareader provide high-performance access to read-only data and is the best choice for accessing data to be displayed in ASP.NET. • DataReader objects can not be created directly in code as they are constructed by calling the ExecuteReader method of a Command object
  • 8. SqlDataAdapter The SqlDataAdapter class is used as a bridge between the DataSet class and SQL Server. You can use the SqlDataAdapter class to create a dataset from a given SQL statement or stored procedure represented by a SqlCommand instance, to update the back-end SQL Server database based on the contents of a dataset, or to insert rows into or delete rows from a SQL Server database. • It provides an automated bridge between a Connection object and a DataSet object • A DataAdapter object contains four Command objects, one each, for SELECT, UPDATE, INSERT and DELETE based SQL statements
  • 9. Sample 1 SqlConnection com; SqlTransaction tran; try { con = new SqlConnection(connectionString); con.open(); tran = con.BeginTransaction(); SqlCommand cmd = new SqlCommand(“DELETE FROM Customers”, con); cmd.Transaction = tran; cmd.ExecuteNonQuery(); } catch (SqlException ex) { if(tran!=null) tran.Rollback(); } finally { if(con!=null) con.Close(); }
  • 10. Sample 2 SqlConnection com; SqlTransaction tran; try { con = new SqlConnection(connectionString); con.open(); SqlCommand cmd = new SqlCommand(“SELECT * FROM Customers”, con); SqlDataReader rdr = cmd.ExecuteReader(); while(rdr.Read()) { Console.WriteLine(rdr[0]); } } catch (SqlException ex) { if(tran!=null) tran.Rollback(); } finally { if(rdr!=null) rdr.Close(); if(con!=null) con.Close(); }
  • 11. Data Sets • The DataSet object is a memory resident copy of data • The DataSet can be considered a somewhat simplified relational database as it models tables and any relationships between them • The DataSet is always disconnected from the data source • The DataSet is composed of two primary objects • The DataTableCollection, accessed through the Tables property • The DataRelationCollection, accessed through the Relations property
  • 12. …cont • The member or child objects in the DataSet object
  • 13. Sample 3 SqlConnection com; SqlTransaction tran; try { con = new SqlConnection(connectionString); con.open(); SqlCommand cmd = new SqlCommand(“SELECT * FROM Customers”, con); SqlDataReader rdr = cmd.ExecuteReader(); DataTable tbl = new DataTable(“MYTABLE1”); tbl.Load(rdr); dataGridView1.DataSource = tbl; } catch (SqlException ex) { if(tran!=null) tran.Rollback(); } finally { if(rdr!=null) rdr.Close(); if(con!=null) con.Close(); }
  • 15. Summary • ADO.NET is the data access component of .NET Framework • Classes are split between Data Providers and Data Sets