每当类型验证失败时,为绑定的 MaskedTextBox 返回 DBNull?

发布于 2024-09-16 06:08:16 字数 317 浏览 2 评论 0原文

我有一个 MaskedTextBox 控件,其掩码为“00/00/0000”、PromptChar“_”和 DateTime 的 ValidatingType,绑定到数据库中也可以接受空值的 DateTime 列。

我希望用户必须输入有效日期,或者将其留空(即“__/__/____”)以获取 DBNull。

通过使用 TypeValidationCompleted 事件,我可以确定是否输入了有效日期,但我不知道如何在未指定日期或指定无效日期时将该值设置为 DBNull。

每当验证失败时,如何从 MaskedTextBox 获取 DBNull 值?

I have a MaskedTextBox control with the mask "00/00/0000", the PromptChar "_" and the ValidatingType of DateTime, bound to a DateTime column in a database that can also accept null values.

I'd like the user to have to enter either a valid date, or leave it blank (i.e. "__/__/____") for a DBNull.

By using the TypeValidationCompleted event I can determine whether a valid date was entered but I do not know how to set the value to a DBNull whenever no date, or an invalid one, is specified.

How can I get a DBNull value from the MaskedTextBox whenever validation fails?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文