We help IT Professionals succeed at work.

Databound Datetimepicker does not save default to database

1,082 Views
Last Modified: 2013-11-07
Hi Experts,

I have a databound DateTimepicker on my form.  If I select a date and save the record it works ok but if I dont select a value (i.e leave the default date)  in nothing is saved to the database.

A previous question i found describes how to set the datetimepicker to blank, how can I set the selected value to automatically save to the database as the current date? - If the default value of the datetimepicker is acceptable, I do not wish the user to have to click it for it to be saved to the database, should it be unnacceptable it would be down to the user to change it to the correct date.

Thanks,
Adam
Comment
Watch Question

Aaron JabamaniTechnical Architect
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Can you show the code you're using ?

Author

Commented:
apeter,

thanks for the code, the line which sets the value, I have changed to:

DateTimePicker.Value = DateTime.Today.ToShortDateString - I have proved this works by using it outside of an if statement.

However, I am having trouble getting it to execute within an if statement, this is because, according to th debugger, when I put a breakpoint on the line:

If DateDateTimePicker.Vaue = Nothing Then

then the DateDateTimePicker.Vaue already equals a date for example: #7/17/2008 10:52:34 AM#.

The problem still exists, in that if I do not run the first line of code above, then the field is saved as null in the database.

Any ideas?

Thanks,
Adam
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Aaron JabamaniTechnical Architect

Commented:
Maybe you should use,  like below, i'm not sure though.

 If [String].IsNullOrEmpty(datepicker.value ) = True Then
                    datepicker.value = myDateTime.ToShortDateString()
end if

There is button to accept mine as solution/answer and award as much as u like :)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.