Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am sending the value for number of days as float from the code behind(c#) and the datatype for number of days in the table is decimal(2.1) but when i send 0.5 as the number of days it is getting saved as 1 into the database how to proceed
Posted
Comments
Herman<T>.Instance 1-Feb-12 5:10am    
use the decimal object in stead of float

If you uses parameterised queries you would not have this problem, as the correct values will be sent to the database.
C#
MySqlCommand cmd = new MySqlCommand("INSERT INTO youTable (numberOfDays) VALUE (@numberOfDays)", yourConnection);
cmd.Parameters.AddWithValue("@numberOfDays", numberOfDays);

This assumes that numberOfDays is your float value.
 
Share this answer
 
Comments
Munawar Hassan 10-Apr-21 5:46am    
with parameterized queries have the same problem.
SQL decimal types are fixed point where as the System.Decimal type is floating point.
However, even then, System.Decimal is the closest match.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900