0

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

Marco
  • 56,740
  • 14
  • 129
  • 152
  • 2
    NULLABLE is not the same as OPTIONAL. You *can* have a non-optional but nullable field. You can also have an optional non-nullable field. – MatBailie May 22 '12 at 06:36

2 Answers2

2

"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

Community
  • 1
  • 1
gbn
  • 422,506
  • 82
  • 585
  • 676
0

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
Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
  • 1
    It works for the resultset but here he wants to know if a parameter is mandatory. I don't think there's a way to known if a parameter is mandatory by code but I'm not 100% sure. – lnu May 22 '12 at 06:08