title: Error CODE : procedure has too many arguments specified
body: <p>I have a this SQL Server stored procedure. When I execute it, I'm getting this error:</p>
  
  <blockquote>
    <p>SQL Server procedure has too many arguments specified </p>
  </blockquote>
  
  <p>How can I solve this problem? Code is shown below.</p>
  
  <p>When my stored procedure is working, I need to do if record exist update then add record. </p>
  
  <pre><code>SET ANSI_NULLS ON 
  GO 
  SET QUOTED_IDENTIFIER ON 
  GO 
  
  ALTER PROCEDURE [dbo].[Insert_MS] 
      (@SID char(20),
       @CREATE_DATETIME char(14),
       @MODIFY_DATETIME char(14),
       @CREATOR_SID char(20), 
       @MODIFIER_SID char(20), 
       @MARK_DELETED char(1), 
       @TARGET_SID nvarchar(20),
       @TARGET_CODE nvarchar(50),
       @UNIT nvarchar(100),
       @SPECIFICATION nvarchar(1000),
       @MATERIALS_SUBCAT nvarchar(1000),
       @SORT int,
       @SET_UNIT nvarchar(1000),
       @ENABLED char(1),
       @MARKET_TYPE nvarchar(2)
      ) 
  AS 
  BEGIN 
      IF EXISTS (SELECT * 
                 FROM [dbo].[M_S] 
                 WHERE [MARKET_TYPE] = @MARKET_TYPE 
                   AND [TARGET_CODE] = @TARGET_CODE 
                   AND [TARGET_SID] = @TARGET_SID) 
      BEGIN 
          --update existing record 
          UPDATE [dbo].[M_S] 
          SET [MATERIALS_SUBCAT] = @MATERIALS_SUBCAT , 
              [SPECIFICATION] = @SPECIFICATION, 
              [UNIT] = @UNIT
          WHERE [MARKET_TYPE] = @MARKET_TYPE 
            AND [TARGET_CODE] = @TARGET_CODE 
            AND [TARGET_SID] = @TARGET_SID 
      END 
      ELSE 
      BEGIN 
          --insert new record 
          INSERT INTO [dbo].[M_S] ([SID], [CREATE_DATETIME], [MODIFY_DATETIME], 
                                   [CREATOR_SID], [MODIFIER_SID], [MARK_DELETED], 
                                   [TARGET_SID], [TARGET_CODE], [UNIT], [SPECIFICATION], 
                                   [MATERIALS_SUBCAT], [SORT], [SET_UNIT],
                                   [ENABLED], [MARKET_TYPE]) 
          VALUES (@SID, @CREATE_DATETIME, @MODIFY_DATETIME,
                  @CREATOR_SID, @MODIFIER_SID, @MARK_DELETED,
                  @TARGET_SID, @TARGET_CODE, @UNIT,
                  @SPECIFICATION, 
                  @MATERIALS_SUBCAT, @SORT, @SET_UNIT,
                  @ENABLED, @MARKET_TYPE) 
      END 
  END
  </code></pre>
  
  <p>Then my aspx.cs code is here </p>
  
  <pre><code>cnn.Open();
  
  insertSql += " INSERT INTO [dbo].[MATERIALS_SUBCAT] ([SID],[CREATE_DATETIME], [MODIFY_DATETIME],";
  insertSql += "  [CREATOR_SID], [MODIFIER_SID], [MARK_DELETED],[TARGET_SID], [TARGET_CODE],";
  insertSql += "  [UNIT], [SPECIFICATION], [MATERIALS_SUBCAT], [SORT],[SET_UNIT], [ENABLED], [MARKET_TYPE])";
  insertSql += " VALUES (@SID, @CREATE_DATETIME, @MODIFY_DATETIME, @CREATOR_SID, @MODIFIER_SID, @MARK_DELETED, @TARGET_SID, @TARGET_CODE, @UNIT, @SPECIFICATION,";
  insertSql += "@MATERIALS_SUBCAT, @SORT, @SET_UNIT, @ENABLED, @MARKET_TYPE)  ";
  
  SqlCommand cmdStoredProcedure = new SqlCommand("Insert_MS", cnn);
  cmdStoredProcedure.CommandType = CommandType.StoredProcedure;
  
  for (int k = 0; k &lt;= dt_sheet.Rows.Count - 1; k++)
  {
      cmdStoredProcedure.Parameters.AddWithValue("@SID", dt_sheet.Rows[k]["SID"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@CREATE_DATETIME", dt_sheet.Rows[k]["CREATE_DATETIME"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@MODIFY_DATETIME", dt_sheet.Rows[k]["MODIFY_DATETIME"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@CREATOR_SID", dt_sheet.Rows[k]["CREATOR_SID"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@MODIFIER_SID", dt_sheet.Rows[k]["MODIFIER_SID"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@MARK_DELETED", dt_sheet.Rows[k]["MARK_DELETED"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@TARGET_SID", dt_sheet.Rows[k]["分類代碼"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@TARGET_CODE", dt_sheet.Rows[k]["品項代碼"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@UNIT", dt_sheet.Rows[k]["單位"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@SPECIFICATION", dt_sheet.Rows[k]["規格"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@MATERIALS_SUBCAT", dt_sheet.Rows[k]["品項名稱"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@SORT", dt_sheet.Rows[k]["SORT"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@SET_UNIT",null);
      cmdStoredProcedure.Parameters.AddWithValue("@ENABLED", dt_sheet.Rows[k]["ENABLED"].ToString());
      cmdStoredProcedure.Parameters.AddWithValue("@MARKET_TYPE", dt_sheet.Rows[k]["MARKET_TYPE"].ToString());
  
      cmdStoredProcedure.ExecuteNonQuery();
      cnn.Close();
  }
  </code></pre>