Oracle® Objects for OLE Developer's Guide 10g Release 1 (10.1) Part Number B10118-01 |
|
See Also |
Quick Tour |
Employee Form |
In our employee application example, we must create global dynaset to which the rest of the program has access. We can create a dynaset that selects all the rows from the "emp" table and assign the resulting dynaset to the global EmpDynaset variable as follows:
Set EmpDynaset = OraDatabase.CreateDynaset("select * from emp", 0&)
The 0& parameter is a bit flag option that specifies the default dynaset state. In the default state, Oracle Objects for OLE will set unset fields to NULL while adding records using DbAddNew. We prefer this behavior since our emp table has no column defaults defined. You can also specify other options to allow server column defaults when adding records. See the CreateDynaset Method for more details.
The code to connect to the server and to create a global dynaset is typically the first thing your Visual Basic application executes. In our example employee application, the Form_Load() procedure creates the OIP server, connects to the database, creates a global dynaset, and calls the function EmpRefresh to display the field values on the Employee form. The code for Form_Load() looks like:
Private Sub Form_Load()
'OraSession and OraDatabase are global
Set OraSession = CreateObject("OracleInProcServer.XOraSession")
Set OraDatabase = OraSession.OpenDatabase("Exampledb", "scott/tiger", 0&)
Set EmpDynaset = OraDatabase.CreateDynaset(
"select * from emp
", 0&)
Call EmpRefresh
End Sub
The following variables are defined globally in EMP_QT.BAS:
Global OraSession As Object
Global OraDatabase As Object
Global EmpDynaset As Object