Oracle® Objects for OLE Developer's Guide 11g Release 2 (11.2) for Microsoft Windows Part Number E17727-03 |
|
|
PDF · Mobi · ePub |
Determines whether the automatic binding of database object parameters will occur. Read/write at design time and run time.
oradata1.AutoBinding = [ True | False
By default, AutoBinding
is True
, in which case the parameters in the OraParameters
collection are bound to the SQL statement of the RecordSource
property before data control refresh (before the SQL statement is executed). Technically speaking, the parameters are rebound when the recordset is re-created.
Setting Autobinding
to False
takes effect only if the SQL statement of the RecordSource
property needs to be rebound and reexecuted. This is not the case when you simply change a parameter value and refresh the data control or simply refresh the recordset (the SQL statement only needs to be reexecuted). This is the case if you alter the RecordSource
property and change the SQL statement.
Use this property to disable all parameter binding when executing a SQL statement that does not contain any parameters (using CreateDynaset
, Refresh
, or ExecuteSQL
).
Changing this property does not take effect until a Refresh
method is sent to the data control (and the appropriate conditions apply). Changing this property has no effect when a recordset.Refresh
is executed.
Integer
(Boolean)
This example demonstrates the use of AutoBinding
to show how it affects data control and recordset refresh. Copy this code into the definition section of a new form containing the Oracle Data Control named oradata1
, Then, press F5 to run.
Sub Form_Load () 'Set the username and password. oradata1.Connect = "scott/tiger" 'Set the databasename. oradata1.DatabaseName = "ExampleDb" 'Refresh the data control without setting the RecordSource. This has the 'effect of creatingthe underlying database object so that parameters 'can be added. oradata1.Refresh 'Set the RecordSource and use a SQL parameter for job. oradata1.RecordSource = "select * from emp where job = :job" 'Add the job input parameter with initial value MANAGER. oradata1.Database.Parameters.Add "job", "MANAGER", 1 'Add the deptno input parameter with initial value 10. oradata1.Database.Parameters.Add "deptno", 10, 1 'Refresh the data control. oradata1.Refresh MsgBox "Employee #" & oradata1.Recordset.fields("empno") & ", Job=" & _ oradata1.Recordset.fields("job") 'Only employees with job=MANAGER will be contained in the dynaset. 'Turn off Automatic parameter binding. oradata1.AutoBinding = False 'Change the value of the job parameter to SALESMAN. oradata1.Database.Parameters("job").Value = "SALESMAN" 'Refresh ONLY the recordset. oradata1.Recordset.Refresh MsgBox "Employee #" & oradata1.Recordset.fields("empno") & ", Job=" & _ oradata1.Recordset.fields("job") 'The query will still execute even with AutoBinding=False 'because the dynaset has not been re-created. 'Set the RecordSource and use a SQL parameter for deptno. oradata1.RecordSource = "select * from emp where deptno = :deptno" On Error GoTo paramerr 'Attempt to refresh the data control. An error should occur, because ' AutoBind=False, the SQL statement contains a parameter, and the 'SQL statement needs to be bound before execution. oradata1.Refresh Exit Sub paramerr: MsgBox oradata1.Database.Session.LastServerErrText Exit Sub End Sub