1

Trying to execute this code:

process.POPManagerPreparation.JudgementPercentage = (decimal?)txtAlternativePercentage.Value;

That works fine, but when the code Context.Current.SaveChanges(); is executed to save it in the database this ArgumentException occurs:

An error occurred while updating the entries. See the inner exception for details.
System.ArgumentException: Parameter value '3,0000' is out of range.

It's definitely about the field i've added, I know because of the value. (it changes when I check with other input)

I tried to change my computer settings from NL-nl to US-en, because it feels like there is something wrong with that but didn't solve it, the same error still exist.

Also tried some things on the text field, same error still:

    <telerik:RadNumericTextBox MinValue="0" MaxLength="100" ID="txtAlternativePercentage"
     runat="server" Type="Percent" Culture="en-US" Width="80px" LabelCssClass=""
     Label="Verhogingspercentage:" LabelWidth="130" AutoPostBack="true"
     OnTextChanged="SalaryChanged" Visible="false">
             <NumberFormat DecimalDigits="1" />
             <IncrementSettings InterceptArrowKeys="False" InterceptMouseWheel="False" />
    </telerik:RadNumericTextBox>

To be complete, the database field is: decimal(10, 5) so that's seems to be alright too. Found online a lot of issues with people that used too small fields but nothing on my issue.

Kunal Kakkad
  • 653
  • 6
  • 19
Ravenix
  • 1,010
  • 4
  • 15
  • 40
  • `` and you try to store 4 decimal digits, maybe that's causing the error? – Alexander Derck Dec 29 '15 at 12:50
  • 1
    better to use float and double because because error showing binary floating types not decimal floating types where the value exact in decimal foramt like 123.345 then you can use decimal otherwise float and double are best option for more info http://stackoverflow.com/questions/618535/difference-between-decimal-float-and-double-in-net you can follow this link ,hope it will helpful for you. – Pankaj Gupta Dec 29 '15 at 12:51
  • @AlexanderDerck I never say something about 4 decimals in the code, only in the textfield to `` I think the problem occurs after I cast it to a Decimal – Ravenix Dec 29 '15 at 12:52
  • You can try specifying the precision in your modelbuilder, did you let EF generate your models? – Alexander Derck Dec 29 '15 at 12:53

2 Answers2

1

You can specify the precision of your properties in your modelBuilder:

modelBuilder.Entity<POPManagerPreparation>()
            .Property(e => e.JudgementPercentage)
            .HasPrecision(10,5);
Alexander Derck
  • 13,818
  • 5
  • 54
  • 76
0

I solved it by changing to a float field like Pankaj Gupta suggested. This works fine.

so I've learned to not use a decimal unless you are sure that the value is strict about the decimal form it expects.

Ravenix
  • 1,010
  • 4
  • 15
  • 40