備考
デフォルトではAutoBinding
はTrue
で、その場合、データ・コントロールのリフレッシュ(SQL文の実行)の前に、OraParameters
コレクションのパラメータはRecordSource
プロパティのSQL文にバインドされます。技術的に表すと、パラメータはレコードセットが再作成される際に再バインドされます。
Autobinding
のFalse
設定は、RecordSource
プロパティのSQL文を再バインドして再実行する必要がある場合にのみ、有効になります。単にパラメータ値を変更してデータ・コントロールをリフレッシュする場合、または単にレコードセットをリフレッシュする場合(SQL文は再実行のみが必要)は該当しません。RecordSource
プロパティを変更してSQL文を変更する場合は該当します。
このプロパティは、パラメータを含まないSQL文の実行時にすべてのパラメータのバインディングを無効にする場合にも使用します(CreateDynaset
、Refresh
またはExecuteSQL
を使用)。
このプロパティへの変更は、Refresh
メソッドがデータ・コントロールに送信された後(および該当条件が適用された後)に有効になります。このプロパティへの変更は、recordset.Refresh
が実行される場合は無効です。
例
この例では、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