This is a migrated thread and some comments may be shown as answers.

When RadDatePicker has no value

6 Answers 112 Views
Input
This is a migrated thread and some comments may be shown as answers.
illumination
Top achievements
Rank 2
illumination asked on 08 Jul 2010, 02:25 PM

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

Sort by
0
Dimo
Telerik team
answered on 08 Jul 2010, 05:00 PM
Hello illumination,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
illumination
Top achievements
Rank 2
answered on 08 Jul 2010, 05:04 PM
Thank you for the Reply.
<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>
This is my aspx code. I still can't see what is the problem. Why is it inserting 1900 instead of NULL value.
Thank you
0
Dimo
Telerik team
answered on 08 Jul 2010, 05:09 PM
Hello illumination,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
illumination
Top achievements
Rank 2
answered on 08 Jul 2010, 07:38 PM
I am successfully getting rid of the 1900 and providing it with Null value in the table (with no MinDate in DateInput) by doing this:

 

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 
0
illumination
Top achievements
Rank 2
answered on 08 Jul 2010, 09:32 PM
When I set MinDate="01/01/1920" SelectedDate="1920-12-08" in my dateinput, Why when I tried to insert the selecteddate for example 1/1/1971 then it inserted 1/1/1980 into the table? How do I fix this?
0
Dimo
Telerik team
answered on 12 Jul 2010, 12:57 PM
Hello Lina,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Input
Asked by
illumination
Top achievements
Rank 2
Answers by
Dimo
Telerik team
illumination
Top achievements
Rank 2
Share this question
or