Cover | Table of Contents | Colophon
' create a reference to a Connection object Dim con As ADODB.Connection ' create a reference to a Recordset object Dim rst AS ADODB.Recordset
' create a new instance of the Connection object Set con = New ADODB.Connection ' create a new instance of the Recordset object Set rst = New ADODB.Recordset
' which object model is this from? Dim rst As Recordset ' explicitly specifying the Data Access Object Model Dim rstDAO As DAO.Recordset ' explicitly specifying the ActiveX Data Object Model Dim rstADO As ADODB.Recordset
#import
keyword. This approach offers not only the most control to the
developer, but it also allows the developer to code in a Visual Basic
programming style.
#import keyword is used in Visual C++ applications
to import information from a type library. To make ADO.ACcessible to
your C++ code, use the following #import
directive:
#import <msado15.dll> no_namespace rename("EOF", "EOFile")#import statement does a couple of things.
First, at compile time it creates a header file with a
.tlh extension, which stands
for
Type Library Header.
This header file is comprised of enumerated types and definitions for
the objects contained in the type library for
msado15.dll.
rename attribute in the statement: rename("EOF", "EOFile") EOF keyword from the type library and
calls it EOFile so that it does not conflict with Visual C++'s
definition of the EOF property.
struct StartOLEProcess{
StartOLEProcess( ) {
::CoInitialize(NULL);
}
~StartOLEProcess( ) {
::CoUninitialize( );
}
} _start_StartOLEProcess;import com.ms.wfc.data.*;
// define a variable which will be used as a reference to the // Connection object Connection con; // define a variable which will be used as a reference to the // Recordset object Recordset rst;
new keyword and assigning it to the
variable reference you just defined:
' create a new instance of an ADO Connection object con = new Connection( ); ' create a new instance of an ADO Recordset object rst = new Recordset( );
// define a variable which will be used as a reference to the // Connection object and create a new instance for that variable Connection con = new Connection( ); // define a variable which will be used as a reference to the // Recordset object and create a new instance for that variable Recordset rst = new Recordset( );
' remove the objects con = null; rst = null;
<!--#include file="adovbs.inc"-->
<!--#include file="adojavas.inc"-->
// define a variable which will be used as a reference to the // Connection object var con; // define a variable which will be used as a reference to the // Recordset object var rec;
' create a new instance of an ADO Connection object
con = Server.CreateObject("ADODB.Connection");
' create a new instance of an ADO Recordset object
rst = Server.CreateObject("ADODB.Recordset");' remove the objects con = null; rst = null;
#import, to help
create type library information for ADO enumerations (groups of
constants) and interfaces. In addition, OLE must be instantiated
before any ActiveX Data Objects are created at all.
Recordset object on a table in a data source
without explicitly creating a
Connection
object.' declare and instantiate a Recordset
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
' open the Recordset object and implicitly create a Connection
rst.Open "Titles", _
"DSN=BiblioDSN", _
adOpenForwardOnly, _
adLockReadOnly, _
adCmdTable
'
' do something
' close the Recordset and clean up
rst.Close
Set rst = NothingDSN=BiblioDSN tells ADO that the table, Titles, is
in the BiblioDSN data source.Recordset object on a table in a data source
without explicitly creating a
Connection
object.' declare and instantiate a Recordset
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
' open the Recordset object and implicitly create a Connection
rst.Open "Titles", _
"DSN=BiblioDSN", _
adOpenForwardOnly, _
adLockReadOnly, _
adCmdTable
'
' do something
' close the Recordset and clean up
rst.Close
Set rst = NothingDSN=BiblioDSN tells ADO that the table, Titles, is
in the BiblioDSN data source.|
Provider
|
Value
|
|---|---|
|
Microsoft
OLE DB provider for ODBC
|
MSDASQL.1 |
|
Microsoft OLE DB provider for Microsoft
Indexing Service
|
MSIDXS |
|
Microsoft
OLE DB provider for Microsoft Active Directory Service
|
ADSDSOObject |
|
Microsoft OLE DB provider for
Microsoft Jet
|
Microsoft.Jet.OLEDB.4.0 |
|
Microsoft OLE DB provider for SQL Server
|
SQLOLEDB |
|
Microsoft
OLE DB provider for Oracle
|
MSDAORA |
|
Microsoft OLE DB provider for
Internet Publishing
|
Set recordset = connection.Execute (CommandText, RecordsAffected, Options)
connection.Execute CommandText, RecordsAffected, Options
|
Component
|
Description
|
|---|---|
|
connection
|
A currently open Connection object.
|
|
CommandText
|
' begin a new transaction con.BeginTrans ' ' do some manipulation of the data here ' ' commit the manipulations of the data to the data source now con.CommitTrans
Set recordset_name = connection_name.OpenSchema(QueryType, Criteria, SchemaID)
|
Component
|
Description
|
|---|---|
|
recordset_name
|
A valid Recordset object.
|
|
connection_name
|
A currently open Connection object.
|
|
QueryType
|
Indicates what type of schema query to perform on the associated
connection object. This value must be a valid constant that belongs
to the SchemaEnum enumeration. Not all QueryType values are supported
by every data source. See the OpenSchema method in Appendix C, for more information.
|
|
Criteria
|
Optional. Indicates a specific constraint used to perform the query
as defined by the QueryType argument. Criteria values are specific to
each QueryType value, and, because not all QueryTypes are supported
by every data source, neither are all Criteria values.
|
If...Then statements, transactions can be nested.