Link to home
Start Free TrialLog in
Avatar of insuremce
insuremce

asked on

Databound Datetimepicker does not save default to database

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
SOLUTION
Avatar of Aaron Jabamani
Aaron Jabamani
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you show the code you're using ?
Avatar of insuremce
insuremce

ASKER

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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 :)