I’m working on a C# application that imports an Excel file to be uploaded by users of the application. My application uses Entity Framework and SQL Server 2008 database.
In my SQL Server database I have created a column to hold value in this format: 1,565,000.62. I defined the column as decimal hence a corresponding decimal property has been created for the same in my entity class.
However, when I’m adding my values into my entity class, I get an invalid cast exception.
What’s the best datatype to use for this type of value (C# and SQL Server)?
You should use a
floator adoubleI beleive.Check out the 2nd answer at this question Difference between decimal, float and double in .NET?
It talks about how decimals can’t be compared to double or floats without a cast.
Also for the Sql deciaml check out this question and answer: What represents a double in sql server?
It talks about decimal for when you know the exact and talks about decimal in c# being in contrast to C# decimal.