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
.NET ProgrammingVisual Basic.NETEditors IDEs

Avatar of undefined
Last Comment
Aaron Jabamani

8/22/2022 - Mon
SOLUTION
Aaron Jabamani

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jorge Paulino

Can you show the code you're using ?
ASKER
insuremce

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
insuremce

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Aaron Jabamani

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 :)
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy