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

Example: Creating an OraObject

The following example illustrates the use of the CreateOraObject method to insert a value instance. Before running the sample code, make sure that you have the necessary datatypes and tables in the database. See Schema Description used in examples of OraObject/OraRef.

In these examples, the row containing "ADDRESS" is inserted as a value instance in the server.

Dynaset Example

Dim OraSession as OraSession

Dim OraDatabase as OraDatabase

Dim OraDynaset as OraDynaset

Dim AddressNew as OraObject

'Create the OraSession Object.

Set OraSession = CreateObject("OracleInProcServer.XOraSession")

'Create the OraDatabase Object by opening a connection to Oracle.

Set OraDatabase = OraSession.OpenDatabase("ExampleDb",

"scott/tiger", 0&)

'create a dynaset object from person_tab

set OraDynaset = OraDatabase.CreateDynaset("select * from person_tab",

0&)

' create a new Address object in OO4O

set AddressNew = OraDatabase.CreateOraObject("ADDRESS")

'initialize the Address object attribute to new value

AddressNew.Street = "Oracle Parkway"

AddressNew.State = "CA"

'start the dynaset AddNew operation and

'set the Address field to new address value

OraDynaset.Addnew

OraDynaset.Fields("ADDR").Value = AddressNew

OraDynaset.Update

OraParameter Example

Dim OraSession as OraSession

Dim OraDatabase as OraDatabase

Dim OraDynaset as OraDynaset

Dim AddressNew as OraObject

'Create the OraSession Object.

Set OraSession = CreateObject("OracleInProcServer.XOraSession")

'Create the OraDatabase Object by opening a connection to Oracle.

Set OraDatabase = OraSession.OpenDatabase("ExampleDb",

"scott/tiger", 0&)

'create an OraParameter object represent Address object bind Variable

OraDatabase.Parameters.Add "ADDRESS", Null, ORAPARM_INPUT,

ORATYPE_OBJECT, "ADDRESS"

' create a new Address object in OO4O

set AddressNew = OraDatabase.CreateOraObject("ADDRESS")

'initialize the Address object attribute to new value

AddressNew.Street = "Oracle Parkway"

AddressNew.State = "CA"

'set the Address to ADDRESS parameter

Oradatabase.Parameters("ADDRESS").Value = AddressNew

'execute the sql statement which updates Address in the person_tab

OraDatabase.ExecuteSQL ("insert into person_tab values

('Eric',30,:ADDRESS)")