Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working on a windows application.

I am using datetimepicker, a submit button and a checkbox control on one of my forms.

If I click on the checkbox, the datetimepicker would appear and store the desired date into the database once the user hits the submit button.
If the checkbox is not checked, I want the date to be stored as a null field not the default value for empty date.

I have searched lot on this problem.

Please, help me with a simple and straight forward solution.

Thanks!!!
Posted
Updated 2-Jun-11 21:24pm
v3
Comments
Dalek Dave 3-Jun-11 3:24am    
Edited for Grammar and Readability.

1 solution

There is no secret. First of all the database field must be set to allow null entries, and the when you insert the row into the database table, you either specifically create a null value parameter for your sql command like this

C#
cmd.Parameters.AddWithValue("@yourDateField", null);


, or you just leave the field out in your sql query.
 
Share this answer
 
Comments
walterhevedeich 3-Jun-11 4:11am    
Agree. Its a 5.
Ahsan Mirza 3-Jun-11 7:36am    
This has not been working for me.
Can you explain a bit please, as I am novice in programming.
Thanks

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