我有一张表格,其中有几个日期时间类型的列。我使用存储过程向表中插入值。在存储过程中,我有变量可接受null值以插入到表中。我的问题是当我尝试将null值插入到表格的日期时间列中时,它会报错。 我的代码如下。
System.Data.SqlTypes.SqlDateTime getDate;
//set DateTime null
getDate = SqlDateTime.Null;
if (InsertDate.Text == "")
{
cmd1.Parameters["@InsertDate"].Value = getDate;
}
else
{
cmd1.Parameters["@InsertDate"].Value = InsertDate.Text;
}