I am unable to find the answer to this problem which have been bugging me for a long time.
When I try to insert into sql table, I use this insert method:
Dim datDOB as date
datDOB = RadDatePickerDOB.DbSelectedDate ---- since it is not a required field so it can be nothing
Dim cmdAddNewRecord as new sqlCommand("INSERT INTO [Table1] ([DOB]) " & _
"VALUES ('"& datDOB & "')", SqlConnection)
Dim daAddNewRecord As New SqlDataAdapter(cmdAddNewRecord)
Dim dsAddNewRecord As New DataSet
Try
If SqlConnection.State <> ConnectionState.Open Then
SqlConnection.Open()
End If
daAddNewRecord.Fill(dsAddNewRecord)
lblError.Visible = True
lblError.Text = "Data has been submitted successfully."
Catch ex As Exception
lblError.Text = ex.Message.ToString
Finally
If SqlConnection.State <> ConnectionState.Closed Then
SqlConnection.Close()
End If
End Try
It inserted successfully but it insert this date: 1/1/1900 12:00:00 AM which I do not want! I would like to insert nothing or null into the table.
Anybody has any idea?
Thank you.
6 Answers, 1 is accepted
As seen from your code snippet, you have full control over the value which the RadDatePicker returns and how the SQL statement is constructed. If the date picker's DbSelectedDate is Nothing, then you should inspect the properties of the data field in the table's design mode - probably the unwanted date is a default value inserted automatically.
Regards,
Dimo
the Telerik team
<
tr
>
<
td
align
=
"left"
valign
=
"top"
class
=
"style1"
>
<
asp:Label
ID
=
"lblDOB"
runat
=
"server"
Text
=
"Date of Birth:"
></
asp:Label
>
</
td
>
<
td
align
=
"left"
valign
=
"top"
width
=
"325px"
>
<
telerik:RadDatePicker
ID
=
"RadDatePickerDOB"
runat
=
"server"
Culture
=
"English (United States)"
Skin
=
"Office2007"
TabIndex
=
"14"
ToolTip
=
"Please enter your Date of Birth"
>
<
Calendar
ID
=
"CalDOB"
runat
=
"server"
Skin
=
"Office2007"
UseColumnHeadersAsSelectors
=
"False"
UseRowHeadersAsSelectors
=
"False"
ViewSelectorText
=
"x"
>
</
Calendar
>
<
DatePopupButton
HoverImageUrl
=
""
ImageUrl
=
""
TabIndex
=
"14"
/>
<
DateInput
ID
=
"DateDOB"
runat
=
"server"
DateFormat
=
"M/d/yyyy"
DisplayDateFormat
=
"M/d/yyyy"
TabIndex
=
"14"
MinDate
=
"1920/1/1"
>
</
DateInput
>
</
telerik:RadDatePicker
>
</
td
>
<
td
align
=
"left"
></
td
>
</
tr
>
Thank you
As suggested in my previous reply, the problem is not related to the RadDatePicker control and neither to the page markup.
Dimo
the Telerik team
With parDOB
.ParameterName =
"@DOB"
.SqlDbType = SqlDbType.SmallDateTime
.SourceColumn =
"DOB"
.Value = RadDatePickerDOB.SelectedDate
If .Value Is Nothing Then
.Value = DBNull.Value
End If
End With
but the problem now i'm facing is that when I don't have this MinDate then everytime I typed date below 1800, it validated that is not correct (please see image).
Thank you
The default minimum date of RadDatePicker is 1980/1/1. If you want to be able to select earlier dates, please set the MinDate property to a suitable value.
Regarding the problem with the value, which is inserted into the database - did you inspect the properties of the data field, as suggested earlier? What is the date value in the SQL statement?
Kind regards,
Dimo
the Telerik team