Skip Headers
Oracle® Objects for OLE Developer's Guide
11g Release 2 (11.2) for Microsoft Windows

Part Number E17727-03
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

AddNew Method

Applies To

OraDynaset Object

Description

Clears the copy buffer and begins a record insertion operation into the specified dynaset and associated database.

Usage

oradynaset.AddNew
oradynaset.DbAddNew 

Remarks

When an AddNew operation is initiated, values of fields present within the dynaset are maintained in a copy buffer and do not reflect the actual contents of the database.

The values of the fields are modified through the OraField object, and committed with an Update operation or when database movement occurs, which discards the new row. Field values that have not been explicitly assigned are either set to Null or allowed to default by way of the Oracle default mechanism, depending on the Column Defaulting mode of the options flag used when the OpenDatabase method was called. In either case, fields that appear in the database table but not in the dynaset are always defaulted by the Oracle default mechanism.

Internally, records are inserted by the AddNew method using the "INSERT into TABLE (...) VALUES (...)" SQL statement, and are added to the end of the table.

When adding a row that has object, collection, and REF columns, these column values should be set to a valid OraObject, OraCollection, or OraRef interface or to the Null value. The column values can also be set with the automation object returned by the CreateOraObject method. When adding a row having a BLOB, CLOB, or BFILE column, the column value should be set to a valid OraBLOB, OraCLOB, or OraBFILE interface, Null, or Empty. Setting a BLOB, CLOB, and BFILE column to an Empty value inserts an empty LOB value into the database.

Note:

A call to Edit, AddNew, or Delete methods cancels any outstanding Edit or AddNew method calls before proceeding. Any outstanding changes not saved using an Update method are lost during the cancellation.

Examples

This example demonstrates the use of the AddNew and Update methods to add a new record to a dynaset. Copy this code into the definition section of a form. Then, press F5.

Sub Form_Load ()
 
 'Declare variables 
 Dim OraSession As OraSession
 Dim OraDatabase As OraDatabase 
 Dim OraDynaset As OraDynaset 
 
 '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 the OraDynaset Object.
 Set OraDynaset = OraDatabase.CreateDynaset("select * from emp", 0&)
 'Begin an AddNew.
 OraDynaset.AddNew
 
 'Set the field(column) values.
 OraDynaset.Fields("EMPNO").Value = "1000"
 OraDynaset.Fields("ENAME").Value = "WILSON"
 OraDynaset.Fields("JOB").Value = "SALESMAN"
 
 OraDynaset.Fields("MGR").Value = "7698"
 OraDynaset.Fields("HIREDATE").Value = "19-SEP-92"
 OraDynaset.Fields("SAL").Value = 2000
 OraDynaset.Fields("COMM").Value = 500
 OraDynaset.Fields("DEPTNO").Value = 30
 
 'End the AddNew and Update the dynaset.
 OraDynaset.Update
 
 MsgBox "Added one new employee."
 
End Sub