Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..
Posted
Comments
milindaSnow 20-Mar-14 2:26am    
It would be easy if you put relevant piece of code to backup your question..

1 solution

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.
 
Share this answer
 
Comments
Member 9579525 20-Mar-14 4:03am    
it taking as null but other fields like this also taking null and inserting 0.00..problem is only for one filed
coder771 20-Mar-14 6:27am    
what is the datatype of that field?

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