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\'
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.
"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.
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.