QPR
asked on
if selecteddate is null?
vb.net
onClick I pass some form values to my code behind, one of which is a calendar.selecteddate.
If the user leaves this unselected I want to pass the current date to the DB.
I tried
dim StartDate as CalStart.SelectedDate
if StartDate = "" then
StartDate = system.datetime.now
end if
but i get errors converting a datetime to a string (or vice versa)
How can I achieve the above? system.dbnull.value didn't work either
onClick I pass some form values to my code behind, one of which is a calendar.selecteddate.
If the user leaves this unselected I want to pass the current date to the DB.
I tried
dim StartDate as CalStart.SelectedDate
if StartDate = "" then
StartDate = system.datetime.now
end if
but i get errors converting a datetime to a string (or vice versa)
How can I achieve the above? system.dbnull.value didn't work either
try like this
dim StartDate as Datetime
StartDate = CalStart.SelectedDate
if StartDate = "" then
StartDate = system.datetime.now
or
dim StartDate as CalStart.SelectedDate
if StartDate = "" then
StartDate = Convert.ToDatetime(system. datetime.n ow)
dim StartDate as Datetime
StartDate = CalStart.SelectedDate
if StartDate = "" then
StartDate = system.datetime.now
or
dim StartDate as CalStart.SelectedDate
if StartDate = "" then
StartDate = Convert.ToDatetime(system.
ASKER
My question should have read...
dim StartDate as DateTime = CalStart.SelectedDate
Will try your second suggestion when back at work
dim StartDate as DateTime = CalStart.SelectedDate
Will try your second suggestion when back at work
Simply make sure the .SelectedDate property is a valid date _before_ attempting to assign to a Date typed vatriable. Initialise with the current
Dim StartDate as Date
If Not IsDate(CalStart.SelectedDate) then
StartDate = System.DateTime.Now.Date
Else
StartDate = CalStart.SelectedDate
End If
... Initialise with the current date value if it the selected value not valid (ie, nothing selected).
ASKER
using
Dim StartDate as Date
If Not IsDate(CalStart.SelectedDa te) then
StartDate = System.DateTime.Now.Date
Else
StartDate = CalStart.SelectedDate
End If
I get the error
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
Dim StartDate as Date
If Not IsDate(CalStart.SelectedDa
StartDate = System.DateTime.Now.Date
Else
StartDate = CalStart.SelectedDate
End If
I get the error
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
ASKER
using
dim StartDate as date = CalStart.SelectedDate
if StartDate = "" then
StartDate = Convert.ToDatetime(system. datetime.n ow)
I get the error
Conversion from string "" to type 'Date' is not valid.
dim StartDate as date = CalStart.SelectedDate
if StartDate = "" then
StartDate = Convert.ToDatetime(system.
I get the error
Conversion from string "" to type 'Date' is not valid.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what is that for a control?