Using OO4O Automation with Visual Basic
When accessing the Oracle Object Server using the OLE Automation interface and
Visual Basic, you must create each object explicitly, except for the client
object, which is always created automatically. The following code fragment
demonstrates how to create first all of the objects required by a dynaset and then
the dynaset itself.
- Start Visual Basic and create a new project then add the following code to the
Declarations section of a form.
...
' Declare variables
Dim OraSession As OraSession
Dim OraDatabase As OraDatabase
Dim OraDynaset As OraDynaset
Dim OraFields As OraFields
2. Add the following code to the Load procedure associated with the form to
access the display the Oracle data.
' Create the OraSession Object. Notice that this is the
' only object created via the CreateObject method. The
' argument to CreateObject is the name by which the
' OraSession object is known to the OLE system.
Set OraSession = CreateObject("OracleInProcServer.XOraSession")
' Create the OraDatabase Object by opening a
' connection to Oracle.
Set OraExampleDB = OraSession.OpenDatabase("ExampleDb",
"scott/tiger", 0&)
' Create the OraDynaset Object; name it EmpTable.
Set EmpTable = OraExampleDB.CreateDynaset("select * from emp", 0&)
' You can now display or manipulate the data in the
' dynaset named EmpTable. For example:
Set EmpFields = EmpTable.fields
EmpTable.movefirst
Do While Not EmpTable.EOF
MsgBox EmpFields("ename").Value
EmpTable.movenext
Loop
3. Run the form to view the results.
See Quick Tour with Visual Basic for more information on using OO4O with Visual Basic.
Contents