Error when entering monetary value into bank

Asked

Viewed 477 times

-2

I am trying to save the value 137421,20 in a table of Sqlserver with a field of type Numeric(8,2). However I get an error with the description:

"Parameter value 137421,20 is out of range."

I’m trying to insert the value into the field Arquivotrailler_totalvalor

I am using the Entity Framework and my model has the following code:

 public partial class ARQUIVO_GERADO_TRAILLER
    {
        public int ID_Arquivo { get; set; }
        public string ArquivoTrailler_Conteudo { get; set; }
        public int ArquivoTrailler_TotalLinhas { get; set; }
        public decimal ArquivoTrailler_TotalValor { get; set; }
    }

The call in the class that is entering the values is with the code below:

objArquivoGeradoTrailler.ID_Arquivo = 90;
objArquivoGeradoTrailler.ArquivoTrailler_Conteudo = "texto";
objArquivoGeradoTrailler.ArquivoTrailler_TotalLinhas = 477;
objArquivoGeradoTrailler.ArquivoTrailler_TotalValor = 137421,20;

db.ARQUIVO_GERADO_TRAILLER.Add(objArquivoGeradoTrailler);
db.SaveChanges();

I can insert this value directly into the bank table, through an Insert script. But feeding the attribute Arquivotrailler_totalvalue which is of the decimal type I get the error described above.

  • 1

    Change to 137421.20 Note the dot instead of the comma.

  • @bigown already tested, and the mistake persists.

  • It may be some configuration of your data model via Fluent API that may be determining the Range of your field. If possible share your entire context class, or at least the OnModelCreating

  • I was able to identify the error, I was updating the field in the database but not the edmx file. Just increasing hasprecision property and it worked.

1 answer

-1

Good night,

Try using "." instead of "," at the decimal value.

objArquivoGeradoTrailler.ArquivoTrailler_TotalValor = 137421.20;

or you can use the

objArquivoGeradoTrailler.ArquivoTrailler_TotalValor = decimal.Parse(137421,20);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.