日期时间选取器 BindingSource NULL 如果未手动更改

本文关键字:如果 NULL 时间 选取 BindingSource 日期 | 更新日期: 2023-09-27 18:34:38

我对DateTimePicker和bindingsource有问题。

当我从日期时间选择器添加一条新记录而不更改日期时,绑定源将日期设置为 null,因此我的数据库中出现问题

数据绑定代码为:

this.dateDateTimePicker.DataBindings.Add(
    new System.Windows.Forms.Binding("Value", 
         this.storeBindingSource, 
         "date", 
         true));

如果从日期时间选择器中选择一个日期,一切正常!

问题是什么,我该如何解决

日期时间选取器 BindingSource NULL 如果未手动更改

在表单加载时添加<datetimepicker>.Value = DateTime.Now;,并在插入前通过 messabebox 检查<datetimepicker>.Value