Float DBParam to a Money column
Posted On Monday, November 12, 2007 at at Monday, November 12, 2007 by Ben HI ran into a very interesting issue today. I was passing in 0.0100 as a parameter to an SP. When I ran it through debug it did not bring back any records. However, when I called the exact same SP with the exact same params from SQL Server management Studio it worked fine. I fixed it by adding a specific cast to my SP in SQL. The Example is below:
where ShippingCostApplied = Cast(@ShipRateByCube as Money)
I think it might have something to do with the type conversion from .Net into SQL. There is not a money data type in C# that I know of. So, I was storing the data in code as a float. Not sure why the float was not getting converted right, but keep this in mind when messing with the money data type.
In your opionion what is the best data type in SQL to work with money using C#?
Hey Carl, I played with this some more and found that you should use the Double data type when dealing with Money types in SQL Server. Thanks for the comment and I hope this helps.
Double doesnt fit, as it is floating-point type.. Decimal is more appropriate or even SqlMoney