1

My stored procedure in SQL Server looks like this:

ALTER PROC [dbo].[Rd_CreateModifyAssignmentType]
(
    @AssignmentTypeId nvarchar(50),
    @AssignmentTypeName nvarchar(50),
    @mode int,
    @Langtype nvarchar(10)='' 
)

While calling it from C# like this:

SqlHelper.ExecuteNonQuery("Rd_CreateModifyAssignmentType", AssignmentTypeId, AssignmentTypeName, mode);

it throws an exception:

Parameter count does not match Parameter Value count.

I want to call the procedure in C# without passing optional parameters.

Please help me with this.

1
  • Then ask the author of SqlHelper, whatever that is, to allow it in whatever code they're using to call the stored procedure. Commented Jul 1, 2016 at 11:01

2 Answers 2

2

In your code you can write as:

if (Langtype.HasValue)
   cmd.Parameters.AddWithValue("@Langtype", Langtype.Value);

So now what will happen is that your procedure will check for the value of optional parameter. If it will not find any value then the method is not going to add the @Langtype parameter into the command and it will use the default value as '' which you have specified in your database.

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

Comments

-1

Please set default value by null all parameter in stored procedure:

ALTER PROC [dbo].[Rd_CreateModifyAssignmentType]
(
   @AssignmentTypeId nvarchar(50) = null,
   @AssignmentTypeName nvarchar(50) = null,
   @mode int = null,
   @Langtype nvarchar(10) = null 
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.