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

1
  • 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. Commented May 22, 2012 at 6:36

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.