ADO/ADO.NET - Passing Null to SP for INT,BIT datatype input params

Asked By Naresh Kumar on 27-May-10 03:58 AM
Hi All,

I have a storedProcedure with input params datatype int, bit . How can I pass null to the storedProcedure for these
input params from ADO.NET.

Thanks in advance.
Santhosh N replied to Naresh Kumar on 27-May-10 04:05 AM
For this you need to make your SP handle this by either assigning default value if not passed from the Ado.Net and on .Net end you can pass dbnull or you also have nullable types in .net like
int? i; where it can also hold null value...
Super Man replied to Naresh Kumar on 27-May-10 04:35 AM

you can assign null values to them, by creating default argument( highlighted here )


    @param1 VARCHAR(32) = NULL,

    @param2 INT = NULL




EXEC @param1='bar', @param2='2'

EXEC 'bar'



all above three works , if you dont pass any argument, then it will take

defaut argument.