views:

417

answers:

1

I have not worked with parameters in ADO.Net very much. I'm writing a custom .Net data provider (modeled on SqlClient), and have to implement the IsNullable property in my parameter class, which inherits from DbParameter. My data provider will not support stored procedures, so I will only be supporting Input (substitution style) parameters.

The MSDN docs are rather unclear on the functionality of IsNullable, stating "Gets or sets a value that indicates whether the parameter accepts null values." Googling turns up a lot of people confused about what IsNullable does, saying that setting IsNullable to false does not prohibit them from using a parameter will a null value, as they would have expected.

Based on this, I am thinking that perhaps the IsNullable property pertains to usage with a stored procedure, and whether or not the stored procedure's parameter is nullable, not whether the parameter value can be null.

In that case, since I won't have stored procedures, my implementation can just be:

        public override bool IsNullable { get { return false; } set {} }

To avoid having to fiddle around with some test code to see how SqlParameter's implementation of IsNullable works, I'd appreciate it if someone experienced in writing code using parameters could explain IsNullable.

+1  A: 

The IsNullable property is informational. It is helpful when one part of code creates the parameter and another actually uses it. For example, the parameter might be automatically derived from the database, in which case it is helpful to the programmer to be able to see whether or not a null value is likely to be accepted.

This is my understanding of the IsNullable property. I don't actually know of any documentation that "proves" this is actually correct.

binarycoder