如何在日期时间插入null [英] how to insert null in datetime
本文介绍了如何在日期时间插入null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在日期时间中插入空值.我正在使用以下代码,但它将插入为1900-01-01 00:00:00.000
i want to insert null value in datetime. i am using following code but it insert as 1900-01-01 00:00:00.000
con.Open();
string str="insert into table(podate) values(@PO_Date)";
cmd = new SqlCommand(str, con);
cmd.Parameters.Add(new SqlParameter("@PO_Date", SqlDbType.DateTime));
sqldatenull = SqlDateTime.Null;
if (PO_Date == "")
{
cmd.Parameters["@PO_Date"].Value = System.Data.SqlTypes.SqlDateTime.Null;
//cmd.Parameters["@PO_Date"].Value = DBNull.Value;
//cmd.Parameters["@PO_Date"].Value = null;
}
else
{
cmd.Parameters["@PO_Date"].Value = DateTime.Parse(PO_Date);
}
podate插入为:1900-01-01 00:00:00.000;
请帮助我.
podate insert as:1900-01-01 00:00:00.000;
pls help me.
thanking you in advance!!
推荐答案
在表中允许空值,并且在此列中插入值时不传递任何参数.
Allow null values in the table and do not pass any parameter while inserting values in this column.
浏览为SQL Server的DateTime列输入空值 [ ^ ].
在Sql server中,转到表设计视图,然后在podate的Allow Nulls列中打勾.
这将用于解决您的问题.
in the Sql server , go to table design view then tick mark in the Allow Nulls column of podate.
this will be used to sort out your problem.
这篇关于如何在日期时间插入null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文