ORA-01036: illegal variable name / number

1

I have a small problem with my application. The INSERT routine gives me its error:

  

ORA-01036: illegal variable name / number

Remembering that the bank is Oracle and the application in C #. Here is the 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();
}

Follow the field types in the application:

  • ANOMES, ANOMESBASE1, ANOMESBASE2, ANOMESBASE3, COD_COOP: NUMBER
  • ACTIVE, CENTRALIZATION, VLR_SUBTOTAL, VLR_CARTEIRACREDITO: NUMBER (15,2)

Does anyone know the reason for this error?

    
asked by anonymous 01.08.2014 / 15:55

2 answers

2

I think your error is in the past parameters. This error happens mainly when the passed parameters are not the same as those in the query and you can see that your last 2 fields are different from those passed in the Value.

command.Parameters.AddWithValue("iVLRSUBTOTAL", model.vlrSubTotal);
command.Parameters.AddWithValue("iVLRCARTEIRACREDITO", model.vlrCarteiraCredito);


"VALUES (iANOMES, iANOMESBASE1, iANOMESBASE2, iANOMESBASE3, iCOD_COOP, iATIVO, iCENTRALIZACAO, iVLR_SUBTOTAL, iVLR_CARTEIRACREDITO)";

Remove the "_" (Underlines) from the parameters and test again.

    
01.08.2014 / 16:21
2

The first column represents the names in insert and the second represents the names in command.Parameters (where you feed each field of the insert):

1) iANOMES ----------------> iANOMES  
2) iANOMESBASE1 -----------> iANOMESBASE1
3) iANOMESBASE2 -----------> iANOMESBASE2
4) iANOMESBASE3 -----------> iANOMESBASE3
5) iCOD_COOP --------------> iCODCOOP
6) iATIVO -----------------> iATIVO
7) iCENTRALIZACAO ---------> iCENTRALIZACAO
8) iVLR_SUBTOTAL ----------> iVLRSUBTOTAL
9) iVLR_CARTEIRACREDITO ---> iVLRCARTEIRACREDITO

Did you notice anything wrong, specifically on lines 5, 8 and 9? Should not the names be identical? I think this is the problem.

Also check that you do not need to add : in front of each parameter of insert .

    
01.08.2014 / 16:20