本文介绍了空值转换为“默认"值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cmd.ExecuteNonQuery()上使用C#4.0;在SQL Server配置文件的帮助下出现错误,我看到了:

i am using C# 4.0 at cmd.ExecuteNonQuery(); there is an error with the help of SQL server profile i saw that :

cmd.Parameters.Add("@employeeSocialTitle", SqlDbType.Char, 5).Value = employeeSocialTitle;



当employeeSocialTitle为null时,将其替换为 默认值
这会导致错误,因此当employeeSocialTitle值为null时,如何强制其插入null

考虑到



when employeeSocialTitle is null it replace it by default
and that makes error so how can i force it to insert null when the employeeSocialTitle value is null

regards

推荐答案

cmd.Parameters.Add("@employeeSocialTitle", SqlDbType.Char, 5).Value = employeeSocialTitle ?? DBNull.Value;


这篇关于空值转换为“默认"值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 23:57