如何在SQL Server2008中将null值传递给datetime数据类型 [英] how to pass the null value into datetime datatype in sql server2008
本文介绍了如何在SQL Server2008中将null值传递给datetime数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我的数据库中有一个DOB字段,我的表单中有一个文本框,没有输入日期,请单击按钮,但是出现类似
的错误
可为空的对象必须具有一个值."我的代码如
hi all,
I have one DOB field in my database and i have one text box in my form with out enter date am click on button, but i got the error like
"Nullable object must have a value." my code like
if (txtdob.Text == "")
{
DateTime? value = null;
record.DOB = value.Value;
}
else
{
record.DOB = Convert.ToDateTime(txtdob.Text);
}
如何在日期时间字段中插入空值.
请给我打电话.
how to insert null value into date time field.
please tel me the ans..
推荐答案
请尝试一下,
Hi,
Please try this,
record.DOB = System.DBNull.Value;
可能会帮助您....
May be help you....
您可以使用Nullable Types来实现.
You can use Nullable Types to achieve that.
Nullable<DateTime> _myDateTime;
检查空值:
Check for nulls:
if (object.myDateTime != null)
或
or
if (object.myDateTime.HasValue)
希望有帮助.
不要忘记标记对您有帮助的答案! :)
Hope that helps.
Don''t forget to mark answers that helped you! :)
这篇关于如何在SQL Server2008中将null值传递给datetime数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文