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

How to set empty RadDatePicker to null?

1 Answer 71 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Jerald
Top achievements
Rank 1
Jerald asked on 08 Mar 2019, 02:50 PM

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);

1 Answer, 1 is accepted

Sort by
0
Jerald
Top achievements
Rank 1
answered on 08 Mar 2019, 03:50 PM

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

newDocCmd.Parameters.AddWithValue("@docSubDt", rdpSubDt.SelectedDate ?? (object)DBNull.Value);
Tags
DatePicker
Asked by
Jerald
Top achievements
Rank 1
Answers by
Jerald
Top achievements
Rank 1
Share this question
or