Visual Basic ADO Programming: 56:150 Information System Design
Visual Basic ADO Programming: 56:150 Information System Design
Visual Basic ADO Programming: 56:150 Information System Design
Introduction 1
Microsoft ActiveX Data Objects (ADO)
enables you to write an application to
access and manipulate data in a database
server through an OLE DB data provider.
High speed, ease of use, low memory
overhead, and a small disk footprint
Introduction 2
Whats data provider
A control or object that provides data for use
with another control or program. The data
provider makes data connectivity much easier
by hiding most of the implementation of data
storage.
Whats OLE DB
A set of COM-based interfaces provide
applications with uniform access to data stored
in diverse information sources, or data stores
Introduction 3
To use ADO objects in an application, you
must first add a reference to the ADO
component.
Start a Standard EXE project and then
select Project References. In the
Reference window, locate Microsoft
ActiveX Data Objects 2.x Library and
check the box before it.
Main Objects
The ADO object
model defines a
collection of
programmable
objects that can be
used by any of the
Microsoft Visual
languages
Close Method
CN.Close
Set CN = Nothing (remove the Connection
Object from memory)
Connection Example
Dim dbcon as ADODB.Connection
Set dbcon = New ADODB.Connection
dbcon.ConnectionString _
="Provider=MSDASQL.1;Persist Security _
Info=False;Data Source=NWIND"
dbcon.ConnectionTimeout = 10
dbcon.Open
dbcon.close
Set dbcon = Nothing
CommandTypeEnum
adCmdStoreProc
Stored procedure
adCmdTable
adCmdTableDirect
Command Example
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Set cmd = New ADODB.Command
cmd.CommandText = "select distinct ShipCountry
from orders"
cmd.CommandType = adCmdText
Set cmd.ActiveConnection = dbcon
Set rst = New ADODB.Recordset
Set rst = cmd.Execute
Command Example
You can do delete, update, insert using
Command Object with the right sql sentence.
Dim cmd As ADODB.Command
Dim lngAffected As Integer
Set cmd = New ADODB.Command
cmd.ActiveConnection = dbcon
cmd.CommandType = adCmdText
cmd.CommandText = "UPDATE tblOrders SET
ShipCountry = 'United States' WHERE ShipCountry =
'USA'
cmd.Execute lngAffected
adOpenStatic
adOpenKeyset
adOpenDynamic