D
darrel
I have the following right now to enter a date into SQL getting the data
from some pull down menus:
-------------------------------------------------
dim dateCCJApprovedDate as DateTime
if cbx_ccjDateNone.Checked = True then
dateCCJApprovedDate = ctype("", DateTime)
else
dateCCJApprovedDate = ctype(ddl_CCJDateMonth.SelectedValue.tostring &
"/01/" & ddl_CCJDateYear.SelectedValue.tostring,
System.Data.SqlTypes.SqlDateTime)
End If
-------------------------------------------------
That works if there is a date to enter. But fails if there isn't, as "" is a
string and can't be converted to a date/time.
So, I did a bit of googling, and came up with this:
-------------------------------------------------
dim dateCCJApprovedDate as System.Data.SqlTypes.SqlDateTime
if cbx_ccjDateNone.Checked = True then
dateCCJApprovedDate = System.Data.SqlTypes.SqlDateTime.null
else
dateCCJApprovedDate = ctype(ddl_CCJDateMonth.SelectedValue.tostring &
"/01/" & ddl_CCJDateYear.SelectedValue.tostring,
System.Data.SqlTypes.SqlDateTime)
End If
-------------------------------------------------
But I have the opposite problem...I can use the null value, but I can't
convert the second set of data to SQLDateTime.
So, I seem to be trying to use/cast two different types of data to the same
field format in SQL and hence my problem. I'm guessing the second method is
a better approach, but it appears I need to do some sort of intermediate
cast/conversion. Am I on the right track with that line of thinking?
-Darrel
from some pull down menus:
-------------------------------------------------
dim dateCCJApprovedDate as DateTime
if cbx_ccjDateNone.Checked = True then
dateCCJApprovedDate = ctype("", DateTime)
else
dateCCJApprovedDate = ctype(ddl_CCJDateMonth.SelectedValue.tostring &
"/01/" & ddl_CCJDateYear.SelectedValue.tostring,
System.Data.SqlTypes.SqlDateTime)
End If
-------------------------------------------------
That works if there is a date to enter. But fails if there isn't, as "" is a
string and can't be converted to a date/time.
So, I did a bit of googling, and came up with this:
-------------------------------------------------
dim dateCCJApprovedDate as System.Data.SqlTypes.SqlDateTime
if cbx_ccjDateNone.Checked = True then
dateCCJApprovedDate = System.Data.SqlTypes.SqlDateTime.null
else
dateCCJApprovedDate = ctype(ddl_CCJDateMonth.SelectedValue.tostring &
"/01/" & ddl_CCJDateYear.SelectedValue.tostring,
System.Data.SqlTypes.SqlDateTime)
End If
-------------------------------------------------
But I have the opposite problem...I can use the null value, but I can't
convert the second set of data to SQLDateTime.
So, I seem to be trying to use/cast two different types of data to the same
field format in SQL and hence my problem. I'm guessing the second method is
a better approach, but it appears I need to do some sort of intermediate
cast/conversion. Am I on the right track with that line of thinking?
-Darrel