How to set empty RadDatePicker to null?

2 posts, 0 answers
  1. Jerald
    Jerald avatar
    32 posts
    Member since:
    Jan 2016

    Posted 08 Mar Link to this post

    I need to insert "null" into the database when a raddatepicker is empty.  How is this accomplished? I use the following parameter for textboxes and it works just fine:

    newDocCmd.Parameters.AddWithValue("@docReason", !string.IsNullOrEmpty(docReasonTextBox.Text) ? docReasonTextBox.Text : (object)DBNull.Value);

     

    If I try the same for the raddatepicker I get the expected error of "cannot convert from 'object' to 'string'":

    newDocCmd.Parameters.AddWithValue("@docSubDt", !string.IsNullOrEmpty(rdpSubDt.DbSelectedDate) ? rdpSubDt.DbSelectedDate : (object)DBNull.Value);
  2. Jerald
    Jerald avatar
    32 posts
    Member since:
    Jan 2016

    Posted 08 Mar in reply to Jerald Link to this post

    Please disregard - apparently I'm having another senior moment.  This works:

    newDocCmd.Parameters.AddWithValue("@docSubDt", rdpSubDt.SelectedDate ?? (object)DBNull.Value);
Back to Top