Skip Headers

Oracle® Objects for OLE Developer's Guide
10g Release 1 (10.1)

Part Number B10118-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Master Index
Master Index
Go to Feedback page
Feedback

Creating a Dynaset

See Also
Quick Tour
Employee Form

Oracle Objects for OLE lets you browse and update data using an object called a dynaset. When you create the dynaset using the OraDatabase.CreateDynaset() method, you must specify a valid SQL select statement. DbCreateDynaset() returns a pointer to the result of the SQL select statement.

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