如何传递null整数值storedprocedure? [英] How to pass null integer value storedprocedure?

查看:78
本文介绍了如何传递null整数值storedprocedure?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将空整数值传递给数据库,从前端代码后面作为参数。那么如何通过null值可以帮助我吗?



I want to pass null integer value into database, from front end code behind as parameter. So how can i pass null values can any one help me please?

cmd.Parameters.Add("@HospitalId", SqlDbType.Int).Value = int.Parse(ddlHospital.SelectedValue.ToString());



我正在使用这个但是我收到错误就无法将字符串值转换为in32





推荐答案

您可以使用DBNull.Value [ ^ ]设置空值。

You can use DBNull.Value[^] to set a null value.
cmd.Parameters.Add("@HospitalId", SqlDbType.Int).Value = DBNull.Value;





您还可以创建存储过程的参数默认为NULL [ ^ ],这样你就不需要设置参数了值是必需的。



You could also make the parameter of the stored procedure default to NULL[^], that way you would not need to set the parameter if no value is needed.


这篇关于如何传递null整数值storedprocedure?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆