值得插入空,即使我已经给了一个列的默认淡水河谷 [英] Value Is Inserting Null Even I Have Given Default Vale For A Column

查看:66
本文介绍了值得插入空,即使我已经给了一个列的默认淡水河谷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一些十进制字段的默认值,即0.00,它是Nullable所以当我不插入该列的值时,它应该插入0.00但它插入NULL ..我不明白为什么会发生..plz帮助。 。

i have set default value for some decimal fields i.e 0.00 and it is Nullable so when i dont insert value for that column then it should insert 0.00 but it is inserting NULL..i dont understand why this happens..plz help..

推荐答案

1.如果您的数据库中的字段是允许NULL并且还有一个默认值0.0(就像您说的那样),当您插入或更新新数据时数据库,如果您没有为该字段指定任何值,则该值将是默认值(如您所说)。

2.但是如果你的代码设置提交了NULL值(直接或间接来自用户输入),那么将保存NULL值,因为你设置了该字段的值,并且该字段允许NULL。 br />
3.解决方案是,在MVC Controller类中,保存到数据库之前检查该值为NULL值的字段或UI控件(文本框)。
1.If in your database the filed is allow NULL and has also a default value 0.0 (like you said), when you insert or update new data in the database, if you do not specify any value for that field the value will be the default value (like you said).
2.But if your code set that filed NULL value (directly or indirectly from the user input) the NULL value will be saved, because you set a value for that field and that filed allow NULL.
3.The solution is, in your MVC Controller class, before to save into the database to check that filed or UI control (text box) from where that value come for NULL value.


这篇关于值得插入空,即使我已经给了一个列的默认淡水河谷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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