Stored procedure or function expects parameter which was not supplied

后端 未结 9 1152
梦谈多话
梦谈多话 2021-01-17 08:47

I am trying to insert data into a SQL Server database by calling a stored procedure, but I am getting the error

*Procedure or function \'Insertion\'

相关标签:
9条回答
  • 2021-01-17 09:45

    You need to use this:

    cmd.Parameters.AddWithValue("@Emp_no", @Emp_no);
    cmd.Parameters.AddWithValue("@Emp_name", @Emp_name);
    cmd.Parameters.AddWithValue("@phone", @phone);
    cmd.Parameters.AddWithValue("@Email", @Email);
    cmd.Parameters.AddWithValue("@Password", @Password);
    cmd.Parameters.AddWithValue("@Gender", @Gender);
    cmd.Parameters.AddWithValue("@Dob", @Dob);
    cmd.Parameters.AddWithValue("@Address", @Address);
    cmd.Parameters.AddWithValue("@Designation", @Designation);
    cmd.Parameters.AddWithValue("@Experience", @Experience);
    cmd.Parameters.AddWithValue("@Salary", @Salary);
    cmd.Parameters.AddWithValue("@Doj", @Doj);
    

    Otherwise, it will throw that exception for each of the parameters.

    0 讨论(0)
  • 2021-01-17 09:45

    "There's only one Add method that's obsoleted, the method that accepts a string for the parameter name and an object for the value. As you noted, you should call AddWithValue instead for this scenario."

    http://social.msdn.microsoft.com/Forums/en-US/15bb16a4-0cf1-4289-b677-3b9d98f09298/parametersaddwithvalue-output-parameter-in-adonet-2?forum=adodotnetdataproviders

    Not all Parameter.Add methods are depreciated. How are you suppose to make an OUTPUT parameter? You have to use Parameter.Add for this.

    0 讨论(0)
  • 2021-01-17 09:51

    You need to use SqlCommand.Parameters.AddWithValue:

    cmd.Parameters.AddWithValue("@ParameterName", value);
    

    or SqlCommand.Parameters.Add for other data types:

    cmd.Parameters.Add("@ParameterName", SqlDbType.Int, 5);
    cmd.Parameters["@ParameterName"].Value = value;
    

    SqlCommand.Parameters.AddWithValue replaces the ambiguous overload of Add that took a string and object parameter. See MSDN for more info.

    0 讨论(0)
提交回复
热议问题