Reputation: 1
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
Upvotes: 0
Views: 1089
Reputation: 432261
"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
Upvotes: 2
Reputation: 48568
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
Upvotes: 0