|
Rank: Member Groups: Member
Joined: 12/28/2010 Posts: 10
|
I have a eo DatePicker control on my form. When the user submits and hasn't selected a date, it fills the value with 1/1/0001
My SQL database will not insert this value. I can use
cmd.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = DBNull.Value
and my procedure will run, but can't use
cmd.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = dpStartDate.SelectedDate
as it sees it as 1/1/0001
How can I work around this if my user doesn't select a date since it's not required to do so on the page?
|
|
Rank: Member Groups: Member
Joined: 12/28/2010 Posts: 10
|
I was able to work around it like this.
If dpStartDate.SelectedDateString = "" Then cmd.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = DBNull.Value Else cmd.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = dpStartDate.SelectedDateString End If
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Yes. That will work. You can also check whether SelectedDate equals to DateTime.MinValue. SelectedDate is a DateTime, so it does not have null value.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 12/28/2010 Posts: 10
|
Thanks Admin. I'm just starting to work with these controls. So far they're awesome.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Glad to hear that. Please feel free to let us know if you have any other questions.
Thanks!
|
|