1
I’m having a little problem in my application. The routine of INSERT causes me to make a mistake:
ORA-01036: illegal variable name/number
Remembering that the database is Oracle and the application in C#. Follows code that generates the error:
public void SalvarCampos(ModelCampos model)
{
connectionBanco.ConectarBanco(modelLogin);
String query = "INSERT INTO CARTEIRA_CREDITO (ANOMES, ANOMESBASE1, ANOMESBASE2, ANOMESBASE3, COD_COOP, ATIVO, CENTRALIZACAO, VLR_SUBTOTAL, VLR_CARTEIRACREDITO) " +
"VALUES (iANOMES, iANOMESBASE1, iANOMESBASE2, iANOMESBASE3, iCOD_COOP, iATIVO, iCENTRALIZACAO, iVLR_SUBTOTAL, iVLR_CARTEIRACREDITO)";
OracleCommand command = new OracleCommand(query, connectionRateio.connection);
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("iANOMES", Convert.ToInt32(model.anoMes));
command.Parameters.AddWithValue("iANOMESBASE1", Convert.ToInt32(model.anoMesBase1));
command.Parameters.AddWithValue("iANOMESBASE2",Convert.ToInt32(model.anoMesBase2));
command.Parameters.AddWithValue("iANOMESBASE3", Convert.ToInt32(model.anoMesBase3));
command.Parameters.AddWithValue("iCODCOOP", model.codCoop);
command.Parameters.AddWithValue("iATIVO", model.ativo);
command.Parameters.AddWithValue("iCENTRALIZACAO", model.centralizacao);
command.Parameters.AddWithValue("iVLRSUBTOTAL", model.vlrSubTotal);
command.Parameters.AddWithValue("iVLRCARTEIRACREDITO", model.vlrCarteiraCredito);
try
{
command.ExecuteNonQuery();// <-- ERRO DISPARADO NESSA LINHA!
command.Transaction.Commit();
connectionRateio.FecharConexaoBanco();
}
catch (Exception exc)
{
//Erro
}
connectionBanco.FecharConexaoBanco();
}
Follows the field types in the application:
- ANOMES, ANOMESBASE1, ANOMESBASE2, ANOMESBASE3, COD_COOP: NUMBER
- ACTIVE, CENTRALIZED, VLR_SUBTOTAL, VLR_CARTEIRACREDITO: NUMBER(15,2)
Can anyone explain to me the reason for this mistake?
Update your question with the types of each of the fields of the port_credito (field1,field2...) and the values that are passed to iCampo1, iCampo2...your error is probably of incompatible field/value types
– Dante
Do the variables in the Oracle statements have no prefix required? I have seen JDBC documentation that uses
:iCAMPO1
instead of justCAMPO1
(in query variable only, Addwithvalue equals).– luiscubal
Updated @Dante!
– Matheus Bessa
@luiscubal, I also read about it. I’ve used the prefixes ':' and '@', but it didn’t help.
– Matheus Bessa
Already answered here below! Check it out! D
– Dante