如何将十进制值插入数据库 [英] how to insert decimal values into database

查看:149
本文介绍了如何将十进制值插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我从后面的代码(c#)发送的天数为float值,表中的天数的数据类型为十进制(2.1),但是当我发送的天数为0.5时,它被保存为1数据库如何进行

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

推荐答案

如果使用参数化查询,则不会出现此问题,因为正确的值将被发送到数据库.
If you uses parameterised queries you would not have this problem, as the correct values will be sent to the database.
MySqlCommand cmd = new MySqlCommand("INSERT INTO youTable (numberOfDays) VALUE (@numberOfDays)", yourConnection);
cmd.Parameters.AddWithValue("@numberOfDays", numberOfDays);


假定numberOfDays是您的浮点值.


This assumes that numberOfDays is your float value.


SQL十进制类型是固定点,而System.Decimal类型是浮点.
但是,即使那样,System.Decimal是最接近的匹配.
SQL decimal types are fixed point where as the System.Decimal type is floating point.
However, even then, System.Decimal is the closest match.


这篇关于如何将十进制值插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆