Retrieves parameter information for the command that is specified in the current DB2Command object (this) and populates the Parameters collection.
[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
);
Exception type | Conditions |
---|---|
ArgumentException | |
InvalidOperationException |
|
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.
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.