SetParam type methods for OLEDB
- Last UpdatedJul 22, 2024
- 1 minute read
Frequently, the SQL statement that you use to create a command has parameters encoded in it. In such cases, you must set values for all parameters needed as input by the SQL statement before you run the command.
For data providers accessed through OLEDB, parameters are indicated by identical placeholder characters, and parameters must be indicated by index. The method call Set<Type>ParameterByIndex() accommodates the indexed parameters of OLEDB.
Parameters are usually mapped to a table column, which always has a specific type. The method parameters that you supply with each of the methods in this subsection vary depending on the column type that they map to.
Note: Because parameters are sequentially numbered, it is important that there be no gaps in the sequence. The sequence is checked when the command object with parameters is executed. Gaps cause the command object to fail.
It is necessary to have separate methods because different column types require that you specify different method parameters.
For example a column of type NVarChar requires that you specify a length, while a column type of Decimal requires that you specify precision and scale.
The following method parameters are common across all methods:
-
Parameter Index (Index) – this is 1-based
-
Parameter Value (parameterValue)
You can specify null for parameterValue when the parameterDirection is Output or ReturnValue.
-
Parameter Direction (parameterDirection)
The following are enumerated values:
-
Input
-
InputOutput
-
Output
-
ReturnValue