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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you show the code you're using ?
ASKER
apeter,
thanks for the code, the line which sets the value, I have changed to:
DateTimePicker.Value = DateTime.Today.ToShortDate String - 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
thanks for the code, the line which sets the value, I have changed to:
DateTimePicker.Value = DateTime.Today.ToShortDate
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Maybe you should use, like below, i'm not sure though.
If [String].IsNullOrEmpty(dat epicker.va lue ) = True Then
datepicker.value = myDateTime.ToShortDateStri ng()
end if
There is button to accept mine as solution/answer and award as much as u like :)
If [String].IsNullOrEmpty(dat
datepicker.value = myDateTime.ToShortDateStri
end if
There is button to accept mine as solution/answer and award as much as u like :)