[Solved] Stored procedure has too many arguments in SQL Server and C# but on second entry


I think you didn’t clear the parameters. You should clear it always after your transaction.

cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserId", userId);
cmd.Parameters.AddWithValue("@MonthlyIncomeName", income.MonthIncomeName);
cmd.Parameters.AddWithValue("@MonthlyIncomeAmount", income.MonthIncomeAmount);
cmd.Parameters.AddWithValue("@TotalMonthlyIncome", income.MonthIncomeAmount);
cmd.Parameters.AddWithValue("@Month", insertMonth);
cmd.Parameters.AddWithValue("@Year", insertYear);
cmd.ExecuteNonQuery();

cmd.Parameters.Clear(); // insert this line

And search about AddWithValue vs Add like @cha said that check your parameter types. See this.

1

solved Stored procedure has too many arguments in SQL Server and C# but on second entry