创建ADO对象

为了使用ActiveX数据对象来处理数据,需要参考画面工程中的ActiveX数据对象库。从VBE的工具菜单中选择参考指令然后选择ADO类型库。对象变量被声明为模块级,这意味着在本例中可以应用在所有其他程序中。如果读取它们之后不处理这些记录,那么它们被声明为程序级。

例:创建ADO Recordset

'General Declarations

Dim conODBC As ADODB.Connection

'This stores the link to the database.

Dim adoRS As ADODB.Recordset

'This stores the results of the query.

 

Private Sub InitADO()

     Dim strQuery As String

     On Error GoTo ErrorHandler

 

     'SQL query that ADO will run.

     strQuery = "SELECT Recipe_ID, Recipe_Name, Batch_Size, " _

     & "Milk_Quan, Choc_Quan, Mix_Time, Milk_Type _

     FROM ACCEPT_TEST & "ORDER _BY _Recipe_Name ASC"

 

     Set conODBC = New ADODB.Connection

     'Create ADO Connection Object.

 

     'Connect to the database. Connect string can be DSN-less.

     'This varies by database type.

     conODBC.Open "driver= _

     & " SQL server};server=thunder;uid=sa;pwd=;database=master"

     Set adoRS = New ADODB.Recordset

     'Create ADO Recordset Object.

 

     'Run the query, and set options to allow read/write access.

     adoRS.Open strQuery, conODBC, adOpenDynamic, _

     adLockPessimistic, adCmdText

     Exit Sub

     ErrorHandler:

          HandleError

End Sub

您最近了解过 iFIX 吗 ?

查看最新版 iFIX 的所有新功能。

让 iFIX 帮助您提高效率,降低成本。