how to pass null in c#?


I am trying to pass a null value as string to a function that will send to a sp.

            String v1;
            String v2;
            AssignedName = e.CommandArgument.ToString();
            Activity = null;

            loadActivity(sqlConnection, v1, v2);

Open in new window

I know my sp works. also, if v2 is not null, it works fine. Once I use null, I get the error v2 was not supplied. Any ideas? thanks
Who is Participating?
Dorababu MConnect With a Mentor Senior Software EngineerCommented:
For the procedure you need to pass the number of arguments whether they are optional from code, if you want to make an optional parameter for function then you can change your function to
loadActivity(string con,string v1,string v2=null)

Open in new window

mcrmgAuthor Commented:
thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.