关于datetime为null的时候报错
这是我代码哦
public static int ModifProject(tb_ProjectTable PT)
{
string sql = "Update tb_Project set ProjectName=@ProjectName,ProjectManager=@ProjectManager,ProjectStage=@ProjectStage,ProjectNumber=@ProjectNumber,FilePath=@FilePath,StartTime=@StartTime,EndTime=@EndTime,Bonus=@Bonus,Remarks=@Remarks where ProjectID=@ProjectID";
SqlParameter[] param = new SqlParameter[]
{
new SqlParameter("@ProjectID",PT.ProjectID),
new SqlParameter("@ProjectName",PT.ProjectName),
new SqlParameter("@ProjectManager",PT.ProjectManager),
new SqlParameter("@ProjectStage",PT.ProjectStage),
new SqlParameter("@ProjectNumber",PT.ProjectNumber),
new SqlParameter("@FilePath",PT.FilePath),
new SqlParameter("@StartTime",PT.StartTime),
new SqlParameter("@EndTime",(PT.EndTime!=null ? PT.EndTime : DBNull.Value)),
new SqlParameter("@Bonus",PT.Bonus),
new SqlParameter("@Remarks",PT.Remarks)
};
return DBhelper.ExecuteNonQuery(System.Data.CommandType.Text, sql, param);
}
会报这个错误,应该怎么解决哦
错误 556 无法确定条件表达式的类型,因为“System.DateTime?”和“System.DBNull”之间没有隐式转换
我想的是,如果EndTime不为空,就正常赋给@EndTime值,如果为空,就赋给@EndTime null值哦
------解决方案--------------------new SqlParameter("@EndTime",(PT.EndTime!=null ? (object)PT.EndTime : DBNull.Value))
------解决方案--------------------new SqlParameter("@EndTime",PT.EndTime),