DB2 10.5 for Linux, UNIX, and Windows

DB2Command.DeriveParameters Method

Retrieves parameter information for the command that is specified in the current DB2Command object (this) and populates the Parameters collection.

Namespace:
IBM.Data.DB2
Assembly:
IBM.Data.DB2 (in IBM.Data.DB2.dll)

Syntax

[Visual Basic]
Public Shared Sub DeriveParameters( _
   ByVal command As DB2Command
 _
)
[C#]
public static void DeriveParameters(
   DB2Command
 command
);
[C++]
public: static void DeriveParameters(
   DB2Command
* command
);
[JScript]
public static function DeriveParameters(
   command : DB2Command

);

Parameters

command
The DB2Command that references a stored procedure or a command text from which the parameter information is to be derived. The derived parameters are added to the DB2Command.Parameters collection of the DB2Command.

Exceptions

Exception type Conditions
ArgumentException  
InvalidOperationException
  • Driver does not support returning stored procedure parameter information.
  • TableDirect option is specified for the System.Data.CommandType property.
  • If the StoredProcedure option is specified for the System.Data.CommandType property but the System.Data.CommandText property contains an invalid stored procedure name.
  • If a connection does not exist or a connection is not open when theDB2CommandBuilder.DeriveParameters method is called.
.

Remarks

The DeriveParameters method overwrites any existing parameter information for the DB2Command object.

You can use the DeriveParameters method when CommandType property is set to the CommandType.StoredProcedure or CommandType.Text option. If the CommandType.StoredProcedure option is specified, theCommandText property must contain a valid stored procedure name. If theCommandType.Text option is specified, the CommandText property must contain an SQL statement or a stored procedure call statement with valid parameters.

You should not use the DeriveParameters method on an overloaded stored procedure because all parameters for all qualifying procedures are returned.

By default, theDeriveParameters adds the ReturnValue parameter to the Parameters collection of the DB2Command.

The DeriveParameters requires an extra call to the data server to obtain the information. If the parameter information is known in advance, it is more efficient to populate the parameters collection by setting the information explicitly.

[C#] The following example demonstrate how to retrieve parameter information with the DeriveParameters method:
DB2Connection conn = new DB2Connection(“database=sample;”);
conn.Open();
DB2Command cmd = conn.CreateCommand();
cmd.CommandText = “INSERT INTO TABLE EXAMPLE(C1, C2) VALLUES (?, ?)”;
cmd.DeriveParameters();
In the example, the cmd.Parameters property contains an instance of the ParameterCollection object with two parameters, each with a Size, DB2Type, IsNullable, Direction, Precision, and Scale properties set.