过程或函数spadddepartment指定了太多参数 [英] Procedure or function spadddepartment has too many arguments specified

查看:65
本文介绍了过程或函数spadddepartment指定了太多参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题



我收到错误过程或函数spAddDepartment指定了太多参数。如何解决。



详细信息



时使用存储过程spAddDepartment在mvc5中使用流畅的api将数据插入表部门我得到上面的错误



表部门



Problem

I get error Procedure or function spAddDepartment has too many arguments specified . How to solve it .

Details

when insert data to table department using stored procedure spAddDepartment using fluent api in mvc5 I get error above

Table department

CREATE TABLE [dbo].[Departments](

    [DepartmentID] [int] IDENTITY(1,1) NOT NULL,

    [DepartmentName] [nvarchar](50) NULL,

    [IsActive] [bit] NULL





存储过程spAddDepartment < br $> b $ b



Stored procedure spAddDepartment

ALTER Procedure [dbo].[spAddDepartment]

@DepartmentName    nvarchar(50)

as 

Begin 

  Insert into Departments values(@DepartmentName,1) 

End





部门模型





Department Model

public partial class Department

    {

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]

        public Department()

        {

            Employees = new HashSet<Employee>();

        }



        public int DepartmentID { get; set; }



        [StringLength(50)]

        public string DepartmentName { get; set; }



        public bool? IsActive { get; set; }



        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]

        public virtual ICollection<Employee> Employees { get; set; }

    }





数据库上下文





Database context

protected override void OnModelCreating(DbModelBuilder modelBuilder)

        {



            modelBuilder.Entity<Department>()

.MapToStoredProcedures(p => p.Insert(sp => sp.HasName("spAddDepartment").Parameter(pm => pm.DepartmentName, "DepartmentName")));



        }





部门控制员





Department controller

[HttpPost]

        public ActionResult Insert(Department depart)

        {





            depart.IsActive = true;



            hr.Departments.Add(depart);

            hr.SaveChanges();

            return View(depart);

        }





部门视图





Department view

<div class="form-horizontal">
        <h4>Department</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.DepartmentName, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DepartmentName, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DepartmentName, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.IsActive, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="checkbox">
                    @Html.EditorFor(model => model.IsActive)
                    @Html.ValidationMessageFor(model => model.IsActive, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>





W帽子我试过:





What I have tried:

Procedure Or Function SpAddDepartment Has Too Many Arguments Specified

推荐答案

这是一个非常明确的错误消息,您将不得不调试正在发生的事情,因为我们无法运行您的所有代码。您将多个参数传递给SQL,而存储过程只需要1.



运行SQL事件探查器以查看发送给SQL的确切内容可能会有所帮助这可以帮助您找出问题所在。
This is a very clear error message and you'll have to debug what is happening as we cannot run all your code. You are passing more than one argument to SQL and the Stored Procedure only expects 1.

It may help to run SQL Profiler to see exactly what is being sent to SQL and that may help you track down where the problem is.


这篇关于过程或函数spadddepartment指定了太多参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆