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

AutoBinding Property

Applies To

Oracle Data Control

Description

Determines whether the automatic binding of database object parameters will occur. Read/write at design time and run time.

Usage

oradata1.AutoBinding = [ True | False

Remarks

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.

Data Type

Integer (Boolean)

Example

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