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\'
For others : I just faced the same error because one of my parameters was null. We need to check for it such as :
command.Parameters.AddWithValue("@phone", (object)phone?? DBNull.Value);
Just a headsup, it might save someone a lot of time soul searching. If you have followed the recommendation here, like using AddWithValue in order to pass a paramter on, and you have everything verified and yet you are still getting the error message "Not supplied", check whether you have set the CommandType property of the command object to CommandType.StoredProcedure.
Not setting this property incurs the same message, believe me! Hope it helps someone.
Avoid parameters that have no value with the parameter set being DBNull.value
Your Insertion stored procedure is expecting @Emp_no
(along with about 15 other parameters). You cannot call the stored procedure without passing the parameters.
Take a look at this site for reference:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2
Everywhere you're defining variables, use Parameters.AddWithValue
instead:
cmd.Parameters.AddWithValue("@Emp_no ", Convert.ToInt32(txtbx_Empno.Text));
This is how it can be done
using (var cmd = new SqlCommand("STORED_PROCEDURE_NAME", SqlConnection))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@PARAM_NAME", PARAM_VALUE);
}
Notice that AddWithValue
, and CommandType.StoredProcedure
both are essential.
Same error message still these days scoping multiple problems - my issue was passing a null value to the parameter. The answer is to null check like so:
parameter.Value = (object)yourParamVal ?? DBNULL.Value;