I am getting this message:
" Exception of type 'System.InvalidOperationException' occurred in mscorlib.ni.dll but was not handled in user code "
This problem occurs when my TimePicker dont have any time choosen when I leave it empty.
My code for the TimePicker looks like this;
DateTime break1S = (DateTime)startBreak1.Value;
Its on this row i am getting the message but if i set a time for the picker i dont get an message.
Any ideas?
**
If startBreak1.Value
is a string :
if (startBreak1!= null)
DateTime.TryParse(startBreak1.Value, out break1S);
if it's a Nullable<DateTime>
(and I think it is)
DateTime break1S = startBreak1.HasValue
? startBreak1.Value
: new DateTime()//or anything you want;
or accept that break1S
can be nullable :
var break1S = startBreak1;
解决方案如下所示:
DateTime break1S = startBreak1.Value.HasValue ? startBreak1.Value.Value : DateTime.MinValue;
您可以尝试以下方法:
DateTime break1S = startBreak1.Value.HasValue ? startBreak1.Value.Value : DateTime.MinValue;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.