SlideShare ist ein Scribd-Unternehmen logo
1 von 15
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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (19)

ADO.NET -database connection
ADO.NET -database connectionADO.NET -database connection
ADO.NET -database connection
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
 
Ado.net
Ado.netAdo.net
Ado.net
 
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
 
Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NET
 
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
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2
 
Ado.net
Ado.netAdo.net
Ado.net
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentals
 
Marmagna desai
Marmagna desaiMarmagna desai
Marmagna desai
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
 
Database programming in vb net
Database programming in vb netDatabase programming in vb net
Database programming in vb net
 
Ado.net
Ado.netAdo.net
Ado.net
 
VISUAL BASIC .net data accesss vii
VISUAL BASIC .net data accesss viiVISUAL BASIC .net data accesss vii
VISUAL BASIC .net data accesss vii
 
Visual Basic.Net & Ado.Net
Visual Basic.Net & Ado.NetVisual Basic.Net & Ado.Net
Visual Basic.Net & Ado.Net
 

Ähnlich wie Lecture 6. ADO.NET Overview.

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
 
Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net ArchitectureUmar Farooq
 
Asp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptxAsp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptxsridharu1981
 
Synapseindia dot net development chapter 8 asp dot net
Synapseindia dot net development  chapter 8 asp dot netSynapseindia dot net development  chapter 8 asp dot net
Synapseindia dot net development chapter 8 asp dot netSynapseindiappsdevelopment
 
Data management with ado
Data management with adoData management with ado
Data management with adoDinesh kumar
 
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
 
Data Access Technologies
Data Access TechnologiesData Access Technologies
Data Access TechnologiesDimara Hakim
 
3-ADO.NET.pdf
3-ADO.NET.pdf3-ADO.NET.pdf
3-ADO.NET.pdfManalAg
 
Ado dot net complete meterial (1)
Ado dot net complete meterial (1)Ado dot net complete meterial (1)
Ado dot net complete meterial (1)Mubarak Hussain
 
ADO .NET by Sonu Vishwakarma
ADO .NET by Sonu VishwakarmaADO .NET by Sonu Vishwakarma
ADO .NET by Sonu VishwakarmaSonu Vishwakarma
 
Introduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIRIntroduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIRPeter Elst
 

Ähnlich wie Lecture 6. ADO.NET Overview. (18)

Ado
AdoAdo
Ado
 
Unit4
Unit4Unit4
Unit4
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to ado
 
Ado.net
Ado.netAdo.net
Ado.net
 
LECTURE 14 Data Access.pptx
LECTURE 14 Data Access.pptxLECTURE 14 Data Access.pptx
LECTURE 14 Data Access.pptx
 
Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net Architecture
 
Asp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptxAsp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptx
 
Synapseindia dot net development chapter 8 asp dot net
Synapseindia dot net development  chapter 8 asp dot netSynapseindia dot net development  chapter 8 asp dot net
Synapseindia dot net development chapter 8 asp dot net
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Data management with ado
Data management with adoData management with ado
Data management with ado
 
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
 
Ado.Net
Ado.NetAdo.Net
Ado.Net
 
Data Access Technologies
Data Access TechnologiesData Access Technologies
Data Access Technologies
 
3-ADO.NET.pdf
3-ADO.NET.pdf3-ADO.NET.pdf
3-ADO.NET.pdf
 
Ado
AdoAdo
Ado
 
Ado dot net complete meterial (1)
Ado dot net complete meterial (1)Ado dot net complete meterial (1)
Ado dot net complete meterial (1)
 
ADO .NET by Sonu Vishwakarma
ADO .NET by Sonu VishwakarmaADO .NET by Sonu Vishwakarma
ADO .NET by Sonu Vishwakarma
 
Introduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIRIntroduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIR
 

Mehr von Alexey Furmanov

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

Mehr von Alexey Furmanov (12)

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

Kürzlich hochgeladen

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 

Kürzlich hochgeladen (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 

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