使用带参数的sql语句向数据库中插入null值

向数据库中插入null值,不能直接使用C#中的null,必须使用DBNull.Value

int?height = textBox3.Text.Trim().lengeth==0?null:(int?)Convert.ToInt32(textBox3.text.trim());

Sqlparameter [ ] pms = new Sqlparameter[ ]{

new  Sqlparameter("@height",SqlDbType.Int){Value ==height==null?DBNull.value:(object)height}

}

猜你喜欢

转载自blog.csdn.net/ABC13222880223/article/details/82822340