Stored procedure or function expects parameter which was not supplied

后端 未结 9 1326
梦谈多话
梦谈多话 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:39

    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.

提交回复
热议问题