ComponentOne True DataControl 8.0
Parameterized SQL

In data source mode, TData allows use of SQL statements with parameters for its RecordSource. SQL parameters are accommodated in True DataControl at both design time and run time by using True DataControl parameters.

The ability to allow parameters in SQL queries at design time is an important addition to functionality that is provided by True DataControl. The standard ADO data control (Microsoft ADODC) does not support parameterized SQL statements in its RecordSource; you have to create an ADO recordset at run time and assign it to the ADODC control.

The parameterized SQL functionality is unavailable in True DataControl Lite.

To use a parameterized SQL statement, do the following

  1. Define a parameter for each SQL parameter. This can be done at design time in the Parameters property page. Parameter names (the Name property) are not important, and you can assign them as you choose.

  2. Set the Type property for each parameter to the variant data type of the SQL parameter.

  3. Specify the SQLParameter property for each such parameter. If your SQL parameters are named, it is reasonable to set SQLParameter to the corresponding SQL parameter name. However, since not all databases support named parameters in SQL, the actual value of SQLParameter is not important. What is important is the fact that it is not empty. Correspondence between True DataControl parameters and SQL parameters is established based on their number, and their ordinal position in the collection returned by the Parameters property, and in the SQL statement. True DataControl parameters with an empty SQLParameter do not participate in this correspondence.

  4. Specify the ValueExpression if you want the parameters to be evaluated automatically. Otherwise, write code setting the parameters’ values. For more information, see Accessing parameter values in code.

At design time, you will get correct field information (press the Retrieve Fields button in the Fields property page) from such parameterized SQL statement if you have defined a parameter for each SQL parameter, as described above.

At run time, SQL parameters will be set to the values of corresponding True DataControl parameters, when the SQL statement is executed.

For an example of using parameters with SQL statements, see Tutorial 7 - Parameters and Dynamic SQL.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback