SlideShare a Scribd company logo
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

More Related Content

PPTX
Chapter 3: ado.net
PPT
Ado.net
PPT
ADO.NET
PPT
ADO .Net
PPSX
ADO.NET
PPT
Ado.net
PPTX
Ado.Net Tutorial
PPTX
Ado .net
Chapter 3: ado.net
Ado.net
ADO.NET
ADO .Net
ADO.NET
Ado.net
Ado.Net Tutorial
Ado .net

What's hot (20)

PPTX
ADO.NET by ASP.NET Development Company in india
PPT
Introduction to ADO.NET
PPTX
For Beginners - Ado.net
PPT
Chap14 ado.net
PPT
For Beginers - ADO.Net
PPTX
Ado.net
PPT
ASP.NET 09 - ADO.NET
PDF
Visual Basic.Net & Ado.Net
PPTX
Ch06 ado.net fundamentals
PPT
Ado.net & data persistence frameworks
PPT
Database programming in vb net
PPS
Vb.net session 05
PDF
Ado.net
PPT
Database Connection
PPTX
Ch 7 data binding
PPT
Marmagna desai
PPTX
PPT
ASP.NET 08 - Data Binding And Representation
PPT
ASP.NET Session 11 12
ADO.NET by ASP.NET Development Company in india
Introduction to ADO.NET
For Beginners - Ado.net
Chap14 ado.net
For Beginers - ADO.Net
Ado.net
ASP.NET 09 - ADO.NET
Visual Basic.Net & Ado.Net
Ch06 ado.net fundamentals
Ado.net & data persistence frameworks
Database programming in vb net
Vb.net session 05
Ado.net
Database Connection
Ch 7 data binding
Marmagna desai
ASP.NET 08 - Data Binding And Representation
ASP.NET Session 11 12
Ad

Viewers also liked (17)

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

Similar to ADO.NET -database connection (20)

PPTX
111111112222223333335555555666Unit-4.pptx
PDF
PDF
Data access
PDF
Presentation on the ADO.NET framework in C#
PPTX
Practical OData
DOCX
Ado dot net complete meterial (1)
PPT
Introduction to ado
PDF
RMySQL Tutorial For Beginners
PPT
PDF
Ibi Open Visualizations
DOC
Asp.Net Database
PPT
PPT
Jdbc
PPTX
Data base connectivity and flex grid in vb
PPT
Final Database Connectivity in JAVA.ppt
PPT
Chap3 3 12
PPTX
Latest Advance Animated Ado.Net With JDBC
PPTX
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
PPTX
jdbc concepts in java jdbc programming- programming
PPTX
JDBC2 JDBCJDBCJDBCJDBCJDBCJDBCJDBCJDBCJDBC
111111112222223333335555555666Unit-4.pptx
Data access
Presentation on the ADO.NET framework in C#
Practical OData
Ado dot net complete meterial (1)
Introduction to ado
RMySQL Tutorial For Beginners
Ibi Open Visualizations
Asp.Net Database
Jdbc
Data base connectivity and flex grid in vb
Final Database Connectivity in JAVA.ppt
Chap3 3 12
Latest Advance Animated Ado.Net With JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
jdbc concepts in java jdbc programming- programming
JDBC2 JDBCJDBCJDBCJDBCJDBCJDBCJDBCJDBCJDBC

More from Anekwong Yoddumnern (6)

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

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Machine learning based COVID-19 study performance prediction
PDF
Electronic commerce courselecture one. Pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
Unlocking AI with Model Context Protocol (MCP)
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Advanced methodologies resolving dimensionality complications for autism neur...
Spectral efficient network and resource selection model in 5G networks
Chapter 3 Spatial Domain Image Processing.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Network Security Unit 5.pdf for BCA BBA.
Machine learning based COVID-19 study performance prediction
Electronic commerce courselecture one. Pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Digital-Transformation-Roadmap-for-Companies.pptx
Understanding_Digital_Forensics_Presentation.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

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