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

RadDateInput null problem

3 Answers 154 Views
Input
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 21 May 2008, 08:41 PM
I am having problems with the RadDateInput control.  I have a web page where the user can enter a date in the radDateInput control or leave it blank.  Null values for my date column are ok in my SQL table.  But how can I Update my SQL table if the RadDateInput is blank?  I have tried several things but I always get Null errors or conversion errors.  So if a valid date is entered then I went to save this date.  If the RadDateInput is blank then I want to update the date SQL column with Null.

Thanks,
Bob

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 May 2008, 07:43 AM
Hello Bob,

Thank you for your interest in our RadDateInput control.

One possible approach is to perform a check if there is a selected date and then use an inline SQL to make sure you pass a valid value to the DB.

            command.Parameters.Add("@date", SqlDbType.DateTime); 
 
            if (RadDateInput1.SelectedDate.HasValue == false) 
                command.Parameters["@date"].Value = DBNull.Value; 
            else 
                command.Parameters["@date"].Value = RadDateInput1.SelectedDate.Value; 
 

It is also possible to just set the lowest possible (to SQL) date and then to interpret this as "no selection".

I assume the best option will be to perform a validation and prevent users from entering an invalid date.

Please let me know whether the proposed solution helps.

Kind Regards,
Daniel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
cdikmen
Top achievements
Rank 1
answered on 06 Apr 2009, 01:33 PM
I need to know how to do the reverse. I store "null" date values in the database as "01/01/1900" and want the Date Control to display empty in this scenario.

            If PeoObj.Birthday.ToString <> "" OR PeoObj.Birthday.ToString <> "1/1/1900" Then
                rdBirthday.SelectedDate.Value = CType(PeoObj.Birthday.ToString, Date)
            Else
                rdBirthday.SelectedDate.Value = ?
            End If
0
Princy
Top achievements
Rank 2
answered on 06 Apr 2009, 01:59 PM
Hello,

I guess you want to show the RadDateInput as empty. If so you can try out the Clear() method for that.

VB:
 
rdBirthday.Clear()  

Thanks,
Princy.
Tags
Input
Asked by
Bob
Top achievements
Rank 1
Answers by
Daniel
Telerik team
cdikmen
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or