RadDateInput null problem

4 posts, 0 answers
  1. Bob
    Bob avatar
    87 posts
    Member since:
    Jan 2008

    Posted 21 May 2008 Link to this post

    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
  2. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 26 May 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. cdikmen
    cdikmen avatar
    25 posts
    Member since:
    Aug 2006

    Posted 06 Apr 2009 Link to this post

    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
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Apr 2009 Link to this post

    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.
Back to Top