SQL Parameter IsNullable

馋奶兔 提交于 2019-12-12 03:03:38

问题


Through the SqlParameter class (for C#) I can see parameters in a stored procedure.

How do you know if a parameter is mandatory or not? I tried using IsNullable but it's always false.

Maybe I'm writing a wrong stored procedure, or is IsNullable meant just to set?

Thanks


回答1:


"Optional" simply means there is a default for stored procedure parameters.
Otherwise, all parameters can be NULL: there is no definition constraint to stop this.

You'd have to parse the stored proc T-SQL to see the default, as per this answer Is there a solution for getting the default value of the parameters of a given stored procedure?

And if you can parse the stored proc definition, then you start to lose the encapsulation benefits




回答2:


In Codebehind use this for checking whether database values are null or not

bool isnull = Convert.IsDBNull(yourvalue);

In SQL use ISNULL (check_expression, replacement_value)

select ISNULL(columnname, 0) from tablename


来源:https://stackoverflow.com/questions/10696509/sql-parameter-isnullable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!