The CommitGrid_Click() procedure inserts the grid data into the database. To
do so, this procedure creates a parameter array object for each column in the
EMP table, which corresponds to a column in the grid. We use the parameter AddTable() method to define each parameter array. For example, we define a parameter
array called "EMPNO_ARR" to hold all Employee Number column elements.
After defining the parameter arrays, we populate them with grid column
elements using the Put_Value method.
To commit the parameter array elements to the database, this procedure uses
the CreateSQL() method with a SQL INSERT statement containing the parameter arrays. Since
the CreateSQL() method executes the SQL INSERT statement in addition to creating
a SQL statement object, all column elements (parameter array elements) are
inserted into the EMP table with this one statement.
When an error occurs executing a SQL INSERT statement containing parameter
arrays, the SQL statement object is still created with no explicitly raised error.
To identify such errors, we always check the OraDatabase.LastServerErr and OraDatabase.LastServerErrText properties immediately after executing CreateSQL.
The CreateSQL method updates the database directly and has no effect on the
dynaset EmpDynaset. We must refresh this dynaset to reflect the newly inserted
records by executing DbRefresh.
The CommitGrid_Click() event procedure does the following:
Defines a parameter array for each grid (database) column, using AddTable.
Copies grid column elements into parameter arrays, using the Put_Value method within a nested loop.
Creates a SQL statement object using CreateSQL to insert parameter array elements into the EMP table.
Checks the LastServerErrText and LastServerErr properties to catch SQL statement execution errors.
Refreshes the global dyanset to reflect newly inserted records, using DbRefresh.