Why my oracleParameter doesnt work?
Posted
by
user1824356
on Stack Overflow
See other posts from Stack Overflow
or by user1824356
Published on 2012-12-10T16:39:39Z
Indexed on
2012/12/10
17:03 UTC
Read the original article
Hit count: 155
I'm a .NET developer and this is the first time i work with oracle provider (Oracle 10g and Framework 4.0). When i add parameter to my command in this way:
objCommand.Parameters.Add("pc_cod_id", OracleType.VarChar, 4000).Value = codId;
objCommand.Parameters.Add("pc_num_id", OracleType.VarChar, 4000).Value = numId;
objCommand.Parameters.Add("return_value", OracleType.Number).Direction = ParameterDirection.ReturnValue;
objCommand.Parameters.Add("pc_email", OracleType.VarChar, 4000).Direction = ParameterDirection.Output;
I have no problem with the result. But when a add parameter in this way:
objCommand.Parameters.Add(CreateParameter(PC_COD_ID, OracleType.VarChar, codId, ParameterDirection.Input));
objCommand.Parameters.Add(CreateParameter(PC_NUM_ID, OracleType.VarChar, numId, ParameterDirection.Input));
objCommand.Parameters.Add(CreateParameter(RETURN_VALUE, OracleType.Number, ParameterDirection.ReturnValue));
objCommand.Parameters.Add(CreateParameter(PC_EMAIL, OracleType.VarChar, ParameterDirection.Output));
The implementation of that function is:
protected OracleParameter CreateParameter(string name, OracleType type, ParameterDirection direction)
{
OracleParameter objParametro = new OracleParameter(name, type);
objParametro.Direction = direction;
if (type== OracleType.VarChar)
{
objParametro.Size = 4000;
}
return objParametro;
}
All my result are a empty string. My question is, these way to add parameters are not the same? And if no, what is the difference? Thanks :)
Add:
Sorry i forgot mention "CreateParameter" is a function with multiple implementations the base is the above function, the other use that.
protected OracleParameter CreateParameter(string name, OracleType type, object value, ParameterDirection direction)
{
OracleParameter objParametro = CreateParameter(name, type, value);
objParametro.Direction = direction;
return objParametro;
}
The last parameters doesn't need value because those are output parameter, those bring me data from the database.
© Stack Overflow or respective owner