適用対象
説明
データベース・オブジェクト・パラメータの自動バインディングを実行するかどうかを決定します。設計時および実行時に読取り/書込みができます。
使用方法
oradata1.AutoBinding = [ True | False
備考
デフォルトではAutoBindingはTrueで、その場合、データ・コントロールのリフレッシュ(SQL文の実行)の前に、OraParametersコレクションのパラメータはRecordSourceプロパティのSQL文にバインドされます。技術的に表すと、パラメータはレコードセットが再作成される際に再バインドされます。
AutobindingのFalse設定は、RecordSourceプロパティのSQL文を再バインドして再実行する必要がある場合にのみ、有効になります。単にパラメータ値を変更してデータ・コントロールをリフレッシュする場合、または単にレコードセットをリフレッシュする場合(SQL文は再実行のみが必要)は該当しません。RecordSourceプロパティを変更してSQL文を変更する場合は該当します。
このプロパティは、パラメータを含まないSQL文の実行時にすべてのパラメータのバインディングを無効にする場合にも使用します(CreateDynaset、RefreshまたはExecuteSQLを使用)。
このプロパティへの変更は、Refreshメソッドがデータ・コントロールに送信された後(および該当条件が適用された後)に有効になります。このプロパティへの変更は、recordset.Refreshが実行される場合は無効です。
データ型
Integer(ブール)
例
この例では、AutoBindingの使用方法と、データ・コントロールおよびレコードセットのリフレッシュに与える影響を示します。このコードをoradata1という名前のOracle Data Controlを含む新規フォームの定義セクションにコピーし、その後、[F5]を押して実行します。
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