在SQL DB中从DateTimePicker存储空值 [英] Storing Null Values from DateTimePicker in SQL DB

查看:119
本文介绍了在SQL DB中从DateTimePicker存储空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在Windows应用程序上工作.

我在其中一个表单上使用datetimepicker,一个提交按钮和一个复选框控件.

如果我单击复选框,则一旦用户单击提交"按钮,就会出现datetimepicker并将所需的日期存储到数据库中.
如果未选中此复选框,则我希望日期存储为空字段,而不是空日期的默认值.

我在这个问题上搜索了很多.

请为我提供一个简单直接的解决方案.

谢谢!!!

Hi,

I am working on a windows application.

I am using datetimepicker, a submit button and a checkbox control on one of my forms.

If I click on the checkbox, the datetimepicker would appear and store the desired date into the database once the user hits the submit button.
If the checkbox is not checked, I want the date to be stored as a null field not the default value for empty date.

I have searched lot on this problem.

Please, help me with a simple and straight forward solution.

Thanks!!!

推荐答案

没有秘密.首先必须将数据库字段设置为允许空条目,然后在将行插入数据库表中时,专门为sql命令创建一个空值参数,如下所示:

There is no secret. First of all the database field must be set to allow null entries, and the when you insert the row into the database table, you either specifically create a null value parameter for your sql command like this

cmd.Parameters.AddWithValue("@yourDateField", null);



,或者您只需在SQL查询中保留该字段即可.



, or you just leave the field out in your sql query.


这篇关于在SQL DB中从DateTimePicker存储空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆