Tutorial :How to pass a Nullable into a stored procedure… from F#?


I'm trying to call a stored procedure with an output parameter from F#, so I need to pass an int? value initialized to null. However, F# is resisting my attempts, saying that the object cannot be null. I've read up on the web as to why that is but my problem remains - I need to call that stored procedure. Has anyone got any ideas as to how I can do it? Thanks.


I do not believe that F# has a conversion from null -> empty Nullable. But if you instantiate a Nullable object, it will default to no value. This is the equivalent of passing null in C#/VB.

myStoredProc (new System.Nullable<int>())  


One nice thing that F# allows you to do is to declare "generic value" so you don't have to write the lengthly construction of the value all the time.

let gnull = new System.Nullable<_>();;  

Now you can just use gnull whenever you need to pass null as a nullable to some function:

> let foo (a:System.Nullable<int>) = 0;;  val foo : System.Nullable<int> -> int    > foo gnull;;  val it : int = 0  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »