Mike
Mike

Reputation: 1067

How to solve "Procedure or function has too many arguments specified" exception?

I have several stored procedures for updating different tables. And when I execute them I get the exception as follows

Procedure or function has too many arguments specified

I tried answers found on over the internet but couldn't fix it.
Here is my code for one stored procedure

cmd.CommandText = "update_HS_HR_EMP_BANK_AADM";
cmd.Parameters.Add("@appNo", SqlDbType.VarChar).Value = appNo;
cmd.Parameters.Add("@BRANCH_CODE", SqlDbType.VarChar).Value = branch;
cmd.Parameters.Add("@ACCOUNTNO", SqlDbType.VarChar).Value = account;
cmd.Parameters.Add("@ACCOUNT_TYPE", SqlDbType.VarChar).Value = type;
cmd.ExecuteNonQuery();
cmd.Parameters.Clear(); 

This is my stored procedure

    ALTER PROCEDURE [dbo].[update_HS_HR_EMP_BANK_AADM] 
        @appNo int,
        @BRANCH_CODE VARCHAR(10),
        @ACCOUNTNO VARCHAR(50),
        @ACCOUNT_TYPE VARCHAR(1)        

    AS
    BEGIN

        Update [HS_HR_EMP_BANK_AADM]
        SET
            [BBRANCH_CODE]=@BRANCH_CODE
            ,[EBANK_ACC_NO]=@ACCOUNTNO
            ,[EBANK_ACC_TYPE_FLG]=@ACCOUNT_TYPE
            ,[EBANK_ACTIVE_FLAG]=1
            ,[LAST_MODIFIED_DATE]=GETDATE()
        Where App_no=@appNo
    END

Upvotes: 3

Views: 22897

Answers (2)

Ash
Ash

Reputation: 2605

There are few things that you should try to investigate

Check the connection string to check it is hitting the right database

Try specifying the command type :

cmd.CommandType = System.Data.CommandType.StoredProcedure;

And change the parameter type you are passing in for the appNo from Varchar to Int.

cmd.Parameters.Add("@appNo", SqlDbType.VarChar).Value = appNo;

As per the stored proc, it should be int.

cmd.Parameters.Add("@appNo", SqlDbType.Int).Value = appNo;

Upvotes: 4

Ahmar
Ahmar

Reputation: 3877

Your passing parameter type did not matched. @appNo add as a varchar but it is int in procedure.

change this

cmd.Parameters.Add("@appNo", SqlDbType.VarChar).Value = appNo;

To this

cmd.Parameters.Add("@appNo", SqlDbType.Int).Value = appNo;

Upvotes: 0

Related Questions