IFDOToADOConnection接口

IFDOToADOConnection接口(DataSourcesOleDB)

能够通过workspace从而创建或者连接到一个ADO connection. 它有2个方法,如下所示:



Description
Connect Connects a Workspace object to an ADO connection object.
CreateADOConnection Creates an ADO connection from a Workspace.

 The Connect method connects a workspace object to an ADO (ActiveX Data Objects) connection object. The ADO connection object must exist BUT not be opened, before this method is called. If the ADO connection has any existing properties, they will be over-written.

Connect方法能够通过workspace连接到一个ADO connection, 而这个ADO connection对象是已经存在,并且是没打开的(被new了,但是还没open)。

Dim  m_fdoCon  As  IFDOToADOConnection
Set  m_fdoCon  =   New  FdoAdoConnection

Dim  m_adocon  as  adodb.connection
Set  m_adocon  -   New  adodb.connection

Dim  m_WrkSpcFact  As  IWorkspaceFactory 
Set  m_WrkSpcFact  =   New  AccessWorkspaceFactory
 
Dim  m_accWS  As  IWorkspace
Dim  sPath  as   string
' modify the path to the .mdb file accordingly.
sPath  =   " d:\data\access\us_states.mdb "
 
Set  m_accWS  =  m_WrkSpcFact.OpenFromFile( Trim (sPath),  0 )

m_fdoCon.Connect m_accWS, m_adocon

Dim  adors  as  adodb.recordset
Set  adors  =   new  adodb.recordset

adors.Open 
" Select * from us_states " , m_adoCon, adOpenForwardOnly, adLockOptimistic

 

The CreateADOConnection method creates an ADO (ActiveX Data Objects) connection from a workspace object. The ADO connection object should not exist before this method is called.

 与connect方法相似,CreateADOConnection 方法能够通过workspace连接到一个ADO connection, 而这个ADO connection对象是还不存在的(被定义了,但是没new)。

Dim  m_fdoCon  As  IFDOToADOConnection
Set  m_fdoCon  =   New  FdoAdoConnection

Dim  m_adoCon  As  ADODB.connection

Dim  m_adors  As  ADODB.Recordset
Set  m_adors  =   New  ADODB.Recordset

Dim  m_accWS  As  IWorkspace
Dim  m_WrkSpcFact  As  IWorkspaceFactory

Dim  sPath  As   String , SQLstr  As   String

Set  m_WrkSpcFact  =   New  AccessWorkspaceFactory

' Modify the path to the .mdb file accordingly
sPath  =   " d:\data\access\us_states.mdb "
Set  m_accWS  =  m_WrkSpcFact.OpenFromFile( Trim (sPath),  0 )

Set  m_adoCon  =  m_fdoCon.CreateADOConnection(m_accWS)

SQLstr 
=   " select * from us_states "
m_adors.Open SQLstr, m_adoCon, adOpenForwardOnly, adLockOptimistic

 

你可能感兴趣的:(Connection)