SlideShare une entreprise Scribd logo
1  sur  40
ADO.NET
database connection

@wong
Ref:: http://www.anekwong.com
ADO.NET
• ADO.NET
.NET
• ADO => ActiveX Data Object

.NET
ADO NET Architecture
• NET Framework data providers
• The DataSet
windows Data Sources
Windows Data sources
(data source)

-

-

IDE

,

(bind)
Data Provider
•

Query
•

Object

DataSet
•

VS2005
–
–
–
–

SQL Server Data Provider
OLEDB Data Provider
Oracle Data Provider
ODBC Data Provider

MS SQL Server
MS Access

V.7
Data Provider
• Data Provider
– Connection
– Command
Query
SQL
– DataAdapter
fill
DataSet
– DataReader
result set
read-only

forward-only /
NET Framework Data Providers
NET Framework
data provider

Description

NET Framework Data Provider for SQL Server

Provides data access for Microsoft SQL
Server version 7.0 or later Uses the
System.Data.SqlClient namespace

NET Framework Data Provider for OLE DB

For data sources exposed using OLE DB
Uses the System.Data.OleDb namespace

NET Framework Data Provider for ODBC

For data sources exposed using ODBC Uses
the System.Data.Odbc namespace

NET Framework Data Provider for Oracle

For Oracle data sources The NET Framework
Data Provider for Oracle supports Oracle
client software version 8.1.7 and later, and
uses the System.Data.OracleClient
namespace
Core Objects of NET Framework Data Providers

Object Description
Connection

Establishes a connection to a specific data source The base
class for all Connection objects is the DbConnection class

Command

Executes a command against a data source Exposes
Parameters and can execute within the scope of a
Transaction from a Connection. The base class for all
Command objects is the DbCommand class

DataReader

Reads a forward-only, read-only stream of data from a data
source The base class for all DataReader objects is the
DbDataReader class

DataAdapter

Populates a DataSet and resolves updates with the data
source The base class for all DataAdapter objects is the
DbDataAdapter class
- The NET Framework Data Provider for SQL Server

Imports Provider
Imports System Data SqlClient
- The .NET Framework Data Provider for OLE DB

Imports Provider

Imports System Data OleDb
Driver

Provider

SQLOLEDB

Microsoft OLE DB Provider for SQL Server

MSDAORA

Microsoft OLE DB Provider for Oracle

Microsoft Jet OLEDB 4.0

OLE DB Provider for Microsoft Jet
- The NET Framework Data Provider for ODBC

Imports Provider
Imports System Data Odbc
Driver
SQL Server
Microsoft ODBC for Oracle

Microsoft Access Driver

mdb

- The NET Framework Data Provider for Oracle

Imports Provider
Imports System.Data
Imports System.Data.OracleClient
Choosing a NET Framework Data Provider
Provider

Notes

NET Framework
Data Provider
for SQL Server

Recommended for middle-tier applications using Microsoft SQL Server
7.0 or later
Recommended for single-tier applications using Microsoft Database
Engine MSDE or SQL Server 7.0 or later
Recommended over use of the OLE DB Provider for SQL Server
SQLOLEDB with the NET Framework Data Provider for OLE DB
For SQL Server 6.5 and earlier, you must use the OLE DB Provider for
SQL Server with the NET Framework Data Provider for OLE DB

NET Framework
Data Provider
for OLE DB

Recommended for middle-tier applications using SQL Server 6.5 or
earlier
For SQL Server 7.0 or later, the NET Framework Data Provider for SQL
Server is recommended
Also recommended for single-tier applications using Microsoft Access
databases Use of an Access database for a middle-tier application is
not recommended

NET Framework
Data Provider
for ODBC

Recommended for middle and single-tier applications using ODBC data
sources

NET Framework
Data Provider
for Oracle

Recommended for middle and single-tier applications using Oracle data
sources
2. Data Set Designer
Vs
DataSet

.Net Framework
disconnected data access

(

Data Table)
)

DataSet (
DataSet
ADO NET DataSet
dataSet
Data Table

Customers
Orders

Table Adapter
SME
Table Adapter

Customer
Orders
DataSet
•
DataSet

Disconnected data access
•
– DataTable
dataSet

TableAdapter

TableAdapter
DataSet
DataSet

Tableadapter.Fill(datatable)

Tableadapter
Datatable

DataSet
DataTable TableAdapter
Data Table
Dataset.table(row).field
Dataset
Table
Row
count-1
Field

Dataset

count
Tableadapter.Fill(datatable)
Fill

GetData
GetData
DataTable

TableAdap
D
GetData
Data Binding
Data Binding

(bind)

DataBinding
code

Dat

Dat
ADO NET Sample Application
Option Explicit On
Option Strict On

Provider
SqlClient

Imports System
Imports System Data
Imports System Data SqlClient

Public Class Program
Public Shared Sub Main
Dim connectionString As String GetConnectionString
Dim queryString As String _
SELECT CategoryID, CategoryName FROM dbo Categories;
Using connection As New SqlConnection connectionString
Dim command As SqlCommand connection CreateCommand
command CommandText queryString
Try
connection Open
Dim dataReader As SqlDataReader _
command ExecuteReader
Do While dataReader Read
Console WriteLine vbTab & {0} & vbTab & {1} , _
dataReader 0 , dataReader 1
Loop
dataReader Close
Catch ex As Exception
Console WriteLine ex Message
End Try
End Using
End Sub
Private Shared Function GetConnectionString As String
' To avoid storing the connection string in your code,
' you can retrieve it from a configuration file
Return Data Source local ;Initial Catalog Northwind; _
& Integrated Security SSPI;
End Function
End Class
ADO NET Sample Application
Option Explicit On
Option Strict On

Provider

Imports System
Imports System Data
Imports System Data OleDb
Public Class Program
Public Shared Sub Main
Dim connectionString As String GetConnectionString
Dim queryString As String _
SELECT CategoryID, CategoryName FROM Categories;
Using connection As New OleDbConnection connectionString
Dim command As OleDbCommand connection CreateCommand
command CommandText queryString
Try

OleDb
Try
connection Open
Dim dataReader As OleDbDataReader _
command ExecuteReader
Do While dataReader Read
Console WriteLine vbTab & {0} & vbTab & {1} , _
dataReader 0 , dataReader 1
Loop
dataReader Close
Catch ex As Exception
Console WriteLine ex Message
End Try
End Using
End Sub
Private Shared Function GetConnectionString As String
' To avoid storing the connection string in your code,
' you can retrieve it from a configuration file
' Assumes Northwind mdb is located in c Data folder
Return Provider Microsoft Jet OLEDB 4.0;Data Source _
& c DataNorthwind mdb;User Id admin;Password ;
Just do it!
•
•

OleDB Provider

Northwind
Ms Access
Import
Provider

Imports System.Data.OleDB
Dim objConn As New System.Data.OleDbConnection()
objConn.ConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:Northwind.mdb”
objConn.Open()

objConn.Close()
Command
Sql
Select, Update, Delete, Insert

Dim objComm As New OleDb.OleDbCommand()

Provider
CommandText
objComm.CommandText = “Select * from Employyes”

objComm.ExecuteNonQury
objComm.ExecuteScalar
objComm.ExecuteReader
Command
Sql
Select, Update, Delete, Insert

Dim objComm As New OleDb.OleDbCommand()

Provider
CommandText
objComm.CommandText = “Select * from Employyes”

objComm.ExecuteNonQury
objComm.ExecuteScalar
objComm.ExecuteReader
objComm.ExecuteReader
Set

dataReader
Dim dr As OleDb.OleDbDataReader
dr = objComm.ExcuteReader

Item

DataReader

While dr.read()
Dim myObj As object = dr.Item(3)
Dim myOtherObj As object = dr.Item(“Customer”)
End While
objComm.ExecuteReader
Set

dataReader
Dim dr As OleDb.OleDbDataReader
dr = objComm.ExcuteReader

Item

DataReader

While dr.read()
Dim myObj As object = dr.Item(3)
Dim myOtherObj As object = dr.Item(“Customer”)
End While
DataReader
Click

ListBox1
Dim strSQL As String = “Select CustomerID,CompanyName F
Sub
Dim objConn As New OleDbConnection(StrConn)
Dim objComm As New OleDbCommand(strSQL,objConn)
Dim dr As OleDbDataReader
objConn.Open()
dr = objComm.ExecuteReader()

ListBox1.Items.Add(“
” & ControlChars.Tab & “
Do while dr.Read()
Dim strRecord As String = dr.Item(“CustomerID”).tostring(
Item(“CompanyName”).Tostring()
ListBox1.Items.Add(strRecord)
Loop
DataReader
DataAdapter
DataAdapter => Dim da As New OleDb.OleDbDataAdapter
Method Fill

DataSet => dataAdapter.Fill(dataSet,tab

Dim objConn As New Data.OleDbConnection(“Provider=Microsoft.Jet.OL _
EDB.4.0;Data Source=C:Northwind.mdb”)
Dim strSQL As String = “Select * from Employees”
Dim da As New OleDb.OleDbDataAdapter
Da.SelectCommand = New OleDb.OleDbCommand(strSQL,objConn)
Dim ds As New DataSet
da.Fill(ds,”Employees”)

dataSet
dataSet.Tables(table).rows(row).(field)
textbox1.text = ds.Tables(“employees”).row(0).(“FirstName”)

ds.Tables(“employees”).row(0).(“FirstName”
DataAdapter
Method Update
=> dataAdapter.Update(dataSet,table)
DataSet
•

DataSet
Dim tb As DataTable = ds.Tables(“Employees”)
Dim row As DataRow = tb.NewRow()
row(“FirstName”) = “Chaimard”
row(“LastName”) = “Kama”
tb.Rows.Add(row)


DataSet
Dim tb As DataTable = ds.Tables(“Employees”)
For Each row As DataRow In tb.Rows
if row(“FirstName”) = “Chaimard” Then
row.(“FirstName”) = “Superman”
end if
Next


DataSet
Dim tb As DataTable = ds.Tables(“Employees”)
For Each row As DataRow In tb.Rows
if row(“FirstName”) = “Chaimard” Then
row.dalete()
end if
Next
Binding
Data
• Simple Binding Data
textbox, Label

• Complex Binding Data
ListBox, ComboBox


Simple Binding Data
:
object.DataBindings.Add(propertyName,dataSource,dataMember)
: textbox1.dataBindings.Add(“text”,ds.Tables(“emp”), “FirstName”)



Listbox1.DataSource = ds.Tables(“emp”)
Listbox1.DisplayMember = “FirstName”

:

Complex Binding Data

With cboStudent
ComboBox
.datasource = ds.Tables(“Faculty”)
.displaymember = “DescriptionThai”
.ValueMember = “FacultyCode”
.DataBindings.Add(“SelectValue”,objBS,“facultyCode”)
End with

2.

Student
Student

: me.bindingContext(ds.Tables.(“emp”)).position = 0
: me.bindingContext(ds.Tables.(“emp”)).position +=
1

: me.bindingContext(ds.Tables.(“emp”)).position =1
:
me.bindingContext(ds.Tables.(“emp”)).position =
me.bindingContext(ds.Tables.(“emp”)).count - 1


BindingSource
Dim objBS As New BindingSource
objBS.DataSource =
ds.Tables(“emp”)
(ds.Tables(“emp”)

emp )
: objBS.MoveFirst
: objBS.MoveNext

Contenu connexe

Tendances

Tendances (20)

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
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
 
For Beginners - Ado.net
For Beginners - Ado.netFor Beginners - Ado.net
For Beginners - Ado.net
 
Chap14 ado.net
Chap14 ado.netChap14 ado.net
Chap14 ado.net
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
 
Ado.net
Ado.netAdo.net
Ado.net
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
Visual Basic.Net & Ado.Net
Visual Basic.Net & Ado.NetVisual Basic.Net & Ado.Net
Visual Basic.Net & Ado.Net
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentals
 
Ado.net & data persistence frameworks
Ado.net & data persistence frameworksAdo.net & data persistence frameworks
Ado.net & data persistence frameworks
 
Database programming in vb net
Database programming in vb netDatabase programming in vb net
Database programming in vb net
 
Vb.net session 05
Vb.net session 05Vb.net session 05
Vb.net session 05
 
Ado.net
Ado.netAdo.net
Ado.net
 
Database Connection
Database ConnectionDatabase Connection
Database Connection
 
Ado.net
Ado.netAdo.net
Ado.net
 
Ch 7 data binding
Ch 7 data bindingCh 7 data binding
Ch 7 data binding
 
Marmagna desai
Marmagna desaiMarmagna desai
Marmagna desai
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
 
ASP.NET Session 11 12
ASP.NET Session 11 12ASP.NET Session 11 12
ASP.NET Session 11 12
 

En vedette

ASP.NET Tutorial - Presentation 1
ASP.NET Tutorial - Presentation 1ASP.NET Tutorial - Presentation 1
ASP.NET Tutorial - Presentation 1Kumar S
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NETPeter Gfader
 
Introduction To Dotnet
Introduction To DotnetIntroduction To Dotnet
Introduction To DotnetSAMIR BHOGAYTA
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web ApplicationRishi Kothari
 
OLE-DB vs ODBC
OLE-DB vs ODBCOLE-DB vs ODBC
OLE-DB vs ODBCTom
 
Overview Of ADO .NET from Wingslive.com
Overview Of ADO .NET from Wingslive.comOverview Of ADO .NET from Wingslive.com
Overview Of ADO .NET from Wingslive.comWings Interactive
 
OLAP Basics and Fundamentals by Bharat Kalia
OLAP Basics and Fundamentals by Bharat Kalia OLAP Basics and Fundamentals by Bharat Kalia
OLAP Basics and Fundamentals by Bharat Kalia Bharat Kalia
 
Blend for Visual Studio 2015
Blend for Visual Studio 2015Blend for Visual Studio 2015
Blend for Visual Studio 2015Jiri Danihelka
 
Entity framework and how to use it
Entity framework and how to use itEntity framework and how to use it
Entity framework and how to use itnspyre_net
 
Getting started with entity framework 6 code first using mvc 5
Getting started with entity framework 6 code first using mvc 5Getting started with entity framework 6 code first using mvc 5
Getting started with entity framework 6 code first using mvc 5Ehtsham Khan
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Bhushan Mulmule
 
Mvc pattern and implementation in java fair
Mvc   pattern   and implementation   in   java fairMvc   pattern   and implementation   in   java fair
Mvc pattern and implementation in java fairTech_MX
 
Dotnet differences compiled -1
Dotnet differences compiled -1Dotnet differences compiled -1
Dotnet differences compiled -1Umar Ali
 
05 entity framework
05 entity framework05 entity framework
05 entity frameworkglubox
 

En vedette (17)

Asp.net.
Asp.net.Asp.net.
Asp.net.
 
ASP.NET Tutorial - Presentation 1
ASP.NET Tutorial - Presentation 1ASP.NET Tutorial - Presentation 1
ASP.NET Tutorial - Presentation 1
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
Introduction To Dotnet
Introduction To DotnetIntroduction To Dotnet
Introduction To Dotnet
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
Oledbconnection (clase)
Oledbconnection (clase)Oledbconnection (clase)
Oledbconnection (clase)
 
OLE-DB vs ODBC
OLE-DB vs ODBCOLE-DB vs ODBC
OLE-DB vs ODBC
 
Overview Of ADO .NET from Wingslive.com
Overview Of ADO .NET from Wingslive.comOverview Of ADO .NET from Wingslive.com
Overview Of ADO .NET from Wingslive.com
 
Ado net certificacion 2013
Ado net certificacion 2013Ado net certificacion 2013
Ado net certificacion 2013
 
OLAP Basics and Fundamentals by Bharat Kalia
OLAP Basics and Fundamentals by Bharat Kalia OLAP Basics and Fundamentals by Bharat Kalia
OLAP Basics and Fundamentals by Bharat Kalia
 
Blend for Visual Studio 2015
Blend for Visual Studio 2015Blend for Visual Studio 2015
Blend for Visual Studio 2015
 
Entity framework and how to use it
Entity framework and how to use itEntity framework and how to use it
Entity framework and how to use it
 
Getting started with entity framework 6 code first using mvc 5
Getting started with entity framework 6 code first using mvc 5Getting started with entity framework 6 code first using mvc 5
Getting started with entity framework 6 code first using mvc 5
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1
 
Mvc pattern and implementation in java fair
Mvc   pattern   and implementation   in   java fairMvc   pattern   and implementation   in   java fair
Mvc pattern and implementation in java fair
 
Dotnet differences compiled -1
Dotnet differences compiled -1Dotnet differences compiled -1
Dotnet differences compiled -1
 
05 entity framework
05 entity framework05 entity framework
05 entity framework
 

Similaire à ADO.NET -database connection

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
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to adoHarman Bajwa
 
RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRsquared Academy
 
Ibi Open Visualizations
Ibi Open VisualizationsIbi Open Visualizations
Ibi Open VisualizationsClif Kranish
 
Data base connectivity and flex grid in vb
Data base connectivity and flex grid in vbData base connectivity and flex grid in vb
Data base connectivity and flex grid in vbAmandeep Kaur
 
Final Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.pptFinal Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.pptTabassumMaktum
 
Latest Advance Animated Ado.Net With JDBC
Latest Advance Animated Ado.Net With JDBC Latest Advance Animated Ado.Net With JDBC
Latest Advance Animated Ado.Net With JDBC Tarun Jain
 
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBCBI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBCSimba Technologies
 
Jdbc connectivity
Jdbc connectivityJdbc connectivity
Jdbc connectivityarikazukito
 

Similaire à ADO.NET -database connection (20)

Jdbc
JdbcJdbc
Jdbc
 
Data access
Data accessData access
Data access
 
Practical OData
Practical ODataPractical OData
Practical OData
 
Ado dot net complete meterial (1)
Ado dot net complete meterial (1)Ado dot net complete meterial (1)
Ado dot net complete meterial (1)
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to ado
 
RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For Beginners
 
Ado
AdoAdo
Ado
 
Ibi Open Visualizations
Ibi Open VisualizationsIbi Open Visualizations
Ibi Open Visualizations
 
Asp.Net Database
Asp.Net DatabaseAsp.Net Database
Asp.Net Database
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc
JdbcJdbc
Jdbc
 
Data base connectivity and flex grid in vb
Data base connectivity and flex grid in vbData base connectivity and flex grid in vb
Data base connectivity and flex grid in vb
 
Final Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.pptFinal Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.ppt
 
Chap3 3 12
Chap3 3 12Chap3 3 12
Chap3 3 12
 
Latest Advance Animated Ado.Net With JDBC
Latest Advance Animated Ado.Net With JDBC Latest Advance Animated Ado.Net With JDBC
Latest Advance Animated Ado.Net With JDBC
 
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBCBI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
 
Ado.Net
Ado.NetAdo.Net
Ado.Net
 
Jdbc connectivity
Jdbc connectivityJdbc connectivity
Jdbc connectivity
 
5.C#
5.C#5.C#
5.C#
 
Introduction to ado.net
Introduction to ado.netIntroduction to ado.net
Introduction to ado.net
 

Plus de Anekwong Yoddumnern

Form design by Dreamweaver CS3/CS5
Form design by Dreamweaver CS3/CS5Form design by Dreamweaver CS3/CS5
Form design by Dreamweaver CS3/CS5Anekwong Yoddumnern
 
Error handle-OOP(รูปแบบและลักษณะการ Error ในโปรแกรม)
Error handle-OOP(รูปแบบและลักษณะการ Error ในโปรแกรม)Error handle-OOP(รูปแบบและลักษณะการ Error ในโปรแกรม)
Error handle-OOP(รูปแบบและลักษณะการ Error ในโปรแกรม)Anekwong Yoddumnern
 

Plus de Anekwong Yoddumnern (6)

Android room award 2556
Android room award 2556Android room award 2556
Android room award 2556
 
Form design by Dreamweaver CS3/CS5
Form design by Dreamweaver CS3/CS5Form design by Dreamweaver CS3/CS5
Form design by Dreamweaver CS3/CS5
 
Error handle-OOP(รูปแบบและลักษณะการ Error ในโปรแกรม)
Error handle-OOP(รูปแบบและลักษณะการ Error ในโปรแกรม)Error handle-OOP(รูปแบบและลักษณะการ Error ในโปรแกรม)
Error handle-OOP(รูปแบบและลักษณะการ Error ในโปรแกรม)
 
Ict oop java
Ict oop javaIct oop java
Ict oop java
 
00course syllabus[c languagee]
00course syllabus[c languagee]00course syllabus[c languagee]
00course syllabus[c languagee]
 
Course syllabus[c languagee]
Course syllabus[c languagee]Course syllabus[c languagee]
Course syllabus[c languagee]
 

Dernier

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

ADO.NET -database connection

  • 2. ADO.NET • ADO.NET .NET • ADO => ActiveX Data Object .NET
  • 3. ADO NET Architecture • NET Framework data providers • The DataSet
  • 4. windows Data Sources Windows Data sources (data source) - - IDE , (bind)
  • 5. Data Provider • Query • Object DataSet • VS2005 – – – – SQL Server Data Provider OLEDB Data Provider Oracle Data Provider ODBC Data Provider MS SQL Server MS Access V.7
  • 6. Data Provider • Data Provider – Connection – Command Query SQL – DataAdapter fill DataSet – DataReader result set read-only forward-only /
  • 7. NET Framework Data Providers NET Framework data provider Description NET Framework Data Provider for SQL Server Provides data access for Microsoft SQL Server version 7.0 or later Uses the System.Data.SqlClient namespace NET Framework Data Provider for OLE DB For data sources exposed using OLE DB Uses the System.Data.OleDb namespace NET Framework Data Provider for ODBC For data sources exposed using ODBC Uses the System.Data.Odbc namespace NET Framework Data Provider for Oracle For Oracle data sources The NET Framework Data Provider for Oracle supports Oracle client software version 8.1.7 and later, and uses the System.Data.OracleClient namespace
  • 8. Core Objects of NET Framework Data Providers Object Description Connection Establishes a connection to a specific data source The base class for all Connection objects is the DbConnection class Command Executes a command against a data source Exposes Parameters and can execute within the scope of a Transaction from a Connection. The base class for all Command objects is the DbCommand class DataReader Reads a forward-only, read-only stream of data from a data source The base class for all DataReader objects is the DbDataReader class DataAdapter Populates a DataSet and resolves updates with the data source The base class for all DataAdapter objects is the DbDataAdapter class
  • 9. - The NET Framework Data Provider for SQL Server Imports Provider Imports System Data SqlClient - The .NET Framework Data Provider for OLE DB Imports Provider Imports System Data OleDb Driver Provider SQLOLEDB Microsoft OLE DB Provider for SQL Server MSDAORA Microsoft OLE DB Provider for Oracle Microsoft Jet OLEDB 4.0 OLE DB Provider for Microsoft Jet
  • 10. - The NET Framework Data Provider for ODBC Imports Provider Imports System Data Odbc Driver SQL Server Microsoft ODBC for Oracle Microsoft Access Driver mdb - The NET Framework Data Provider for Oracle Imports Provider Imports System.Data Imports System.Data.OracleClient
  • 11. Choosing a NET Framework Data Provider Provider Notes NET Framework Data Provider for SQL Server Recommended for middle-tier applications using Microsoft SQL Server 7.0 or later Recommended for single-tier applications using Microsoft Database Engine MSDE or SQL Server 7.0 or later Recommended over use of the OLE DB Provider for SQL Server SQLOLEDB with the NET Framework Data Provider for OLE DB For SQL Server 6.5 and earlier, you must use the OLE DB Provider for SQL Server with the NET Framework Data Provider for OLE DB NET Framework Data Provider for OLE DB Recommended for middle-tier applications using SQL Server 6.5 or earlier For SQL Server 7.0 or later, the NET Framework Data Provider for SQL Server is recommended Also recommended for single-tier applications using Microsoft Access databases Use of an Access database for a middle-tier application is not recommended NET Framework Data Provider for ODBC Recommended for middle and single-tier applications using ODBC data sources NET Framework Data Provider for Oracle Recommended for middle and single-tier applications using Oracle data sources
  • 12. 2. Data Set Designer Vs DataSet .Net Framework disconnected data access ( Data Table) ) DataSet ( DataSet
  • 20. ADO NET Sample Application Option Explicit On Option Strict On Provider SqlClient Imports System Imports System Data Imports System Data SqlClient Public Class Program Public Shared Sub Main Dim connectionString As String GetConnectionString Dim queryString As String _ SELECT CategoryID, CategoryName FROM dbo Categories; Using connection As New SqlConnection connectionString Dim command As SqlCommand connection CreateCommand command CommandText queryString
  • 21. Try connection Open Dim dataReader As SqlDataReader _ command ExecuteReader Do While dataReader Read Console WriteLine vbTab & {0} & vbTab & {1} , _ dataReader 0 , dataReader 1 Loop dataReader Close Catch ex As Exception Console WriteLine ex Message End Try End Using End Sub Private Shared Function GetConnectionString As String ' To avoid storing the connection string in your code, ' you can retrieve it from a configuration file Return Data Source local ;Initial Catalog Northwind; _ & Integrated Security SSPI; End Function End Class
  • 22. ADO NET Sample Application Option Explicit On Option Strict On Provider Imports System Imports System Data Imports System Data OleDb Public Class Program Public Shared Sub Main Dim connectionString As String GetConnectionString Dim queryString As String _ SELECT CategoryID, CategoryName FROM Categories; Using connection As New OleDbConnection connectionString Dim command As OleDbCommand connection CreateCommand command CommandText queryString Try OleDb
  • 23. Try connection Open Dim dataReader As OleDbDataReader _ command ExecuteReader Do While dataReader Read Console WriteLine vbTab & {0} & vbTab & {1} , _ dataReader 0 , dataReader 1 Loop dataReader Close Catch ex As Exception Console WriteLine ex Message End Try End Using End Sub Private Shared Function GetConnectionString As String ' To avoid storing the connection string in your code, ' you can retrieve it from a configuration file ' Assumes Northwind mdb is located in c Data folder Return Provider Microsoft Jet OLEDB 4.0;Data Source _ & c DataNorthwind mdb;User Id admin;Password ;
  • 24. Just do it! • • OleDB Provider Northwind Ms Access Import Provider Imports System.Data.OleDB Dim objConn As New System.Data.OleDbConnection() objConn.ConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:Northwind.mdb”
  • 26. Command Sql Select, Update, Delete, Insert Dim objComm As New OleDb.OleDbCommand() Provider CommandText objComm.CommandText = “Select * from Employyes” objComm.ExecuteNonQury objComm.ExecuteScalar objComm.ExecuteReader
  • 27. Command Sql Select, Update, Delete, Insert Dim objComm As New OleDb.OleDbCommand() Provider CommandText objComm.CommandText = “Select * from Employyes” objComm.ExecuteNonQury objComm.ExecuteScalar objComm.ExecuteReader
  • 28. objComm.ExecuteReader Set dataReader Dim dr As OleDb.OleDbDataReader dr = objComm.ExcuteReader Item DataReader While dr.read() Dim myObj As object = dr.Item(3) Dim myOtherObj As object = dr.Item(“Customer”) End While
  • 29. objComm.ExecuteReader Set dataReader Dim dr As OleDb.OleDbDataReader dr = objComm.ExcuteReader Item DataReader While dr.read() Dim myObj As object = dr.Item(3) Dim myOtherObj As object = dr.Item(“Customer”) End While
  • 31. Dim strSQL As String = “Select CustomerID,CompanyName F Sub Dim objConn As New OleDbConnection(StrConn) Dim objComm As New OleDbCommand(strSQL,objConn) Dim dr As OleDbDataReader objConn.Open() dr = objComm.ExecuteReader() ListBox1.Items.Add(“ ” & ControlChars.Tab & “ Do while dr.Read() Dim strRecord As String = dr.Item(“CustomerID”).tostring( Item(“CompanyName”).Tostring() ListBox1.Items.Add(strRecord) Loop
  • 33. DataAdapter DataAdapter => Dim da As New OleDb.OleDbDataAdapter Method Fill DataSet => dataAdapter.Fill(dataSet,tab Dim objConn As New Data.OleDbConnection(“Provider=Microsoft.Jet.OL _ EDB.4.0;Data Source=C:Northwind.mdb”) Dim strSQL As String = “Select * from Employees” Dim da As New OleDb.OleDbDataAdapter Da.SelectCommand = New OleDb.OleDbCommand(strSQL,objConn) Dim ds As New DataSet da.Fill(ds,”Employees”) dataSet dataSet.Tables(table).rows(row).(field) textbox1.text = ds.Tables(“employees”).row(0).(“FirstName”) ds.Tables(“employees”).row(0).(“FirstName”
  • 35. DataSet • DataSet Dim tb As DataTable = ds.Tables(“Employees”) Dim row As DataRow = tb.NewRow() row(“FirstName”) = “Chaimard” row(“LastName”) = “Kama” tb.Rows.Add(row)
  • 36.  DataSet Dim tb As DataTable = ds.Tables(“Employees”) For Each row As DataRow In tb.Rows if row(“FirstName”) = “Chaimard” Then row.(“FirstName”) = “Superman” end if Next
  • 37.  DataSet Dim tb As DataTable = ds.Tables(“Employees”) For Each row As DataRow In tb.Rows if row(“FirstName”) = “Chaimard” Then row.dalete() end if Next
  • 38. Binding Data • Simple Binding Data textbox, Label • Complex Binding Data ListBox, ComboBox
  • 39.  Simple Binding Data : object.DataBindings.Add(propertyName,dataSource,dataMember) : textbox1.dataBindings.Add(“text”,ds.Tables(“emp”), “FirstName”)  Listbox1.DataSource = ds.Tables(“emp”) Listbox1.DisplayMember = “FirstName” : Complex Binding Data With cboStudent ComboBox .datasource = ds.Tables(“Faculty”) .displaymember = “DescriptionThai” .ValueMember = “FacultyCode” .DataBindings.Add(“SelectValue”,objBS,“facultyCode”) End with 2. Student Student
  • 40.  : me.bindingContext(ds.Tables.(“emp”)).position = 0 : me.bindingContext(ds.Tables.(“emp”)).position += 1 : me.bindingContext(ds.Tables.(“emp”)).position =1 : me.bindingContext(ds.Tables.(“emp”)).position = me.bindingContext(ds.Tables.(“emp”)).count - 1  BindingSource Dim objBS As New BindingSource objBS.DataSource = ds.Tables(“emp”) (ds.Tables(“emp”) emp ) : objBS.MoveFirst : objBS.MoveNext