Welcome Guest Search | Active Topics | Sign In | Register

how to insert no date selected? Options
Bobby Lee
Posted: Tuesday, December 28, 2010 9:50:45 AM
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?
Bobby Lee
Posted: Tuesday, December 28, 2010 11:17:22 AM
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
eo_support
Posted: Tuesday, December 28, 2010 3:21:21 PM
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!
Bobby Lee
Posted: Tuesday, December 28, 2010 3:36:10 PM
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.
eo_support
Posted: Tuesday, December 28, 2010 3:50:10 PM
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!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.