INSERT设置为OFF表不能为标识列插入显式值

INSERT设置为OFF表不能为标识列插入显式值

本文介绍了当IDENTITY_INSERT设置为OFF表不能为标识列插入显式值'ClientDetails“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到此异常抛出每当我尝试通过表单提交数据到该数据库: -

I get this exception thrown whenever I try and submit data through a form to this database :-


  • 例外

  • Exception

无法插入时IDENTITY_INSERT设置为OFF标识列'ClientDetails显性价值。

但是,窗体没有一个字段,这样的数据可以输入标识列(PK),所以我很茫然,为什么这正在发生。

However, the form doesn't have a field so data can enter the identity column (PK) so I'm at a loss as to why this is occuring.

目前我使用的是标准的asp.net的MVC提交按钮,但我最终会链接到一个jQuery的对话框按钮

At the moment I'm using the standard asp.net mvc submit button but I will link it eventually to a jquery dialog button

的ClientNo列这是所述列中的异常是指具有以下属性

The ClientNo Column which is the said column the exception is referring to has the following attributes


  • 名称 - ClientNo

  • 类型 - INT

  • NULLS - NO

  • 身份规格 - 是

  • 是一种身份 - 是

  • 增量 - 1

  • 种子 - 1

该ClientNo有数据900起等

The ClientNo has data 900 onwards etc

此异常也扔在客户端表单没有在表格中输入数据。

This exception is also thrown when the client form has no data entered in form

它扔在一个DataCOntext.SubmitChanges()方法

Its thrown on a DataCOntext.SubmitChanges() method

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create1(ClientDetail client)
        {
            if(ModelState.IsValid)
            {
            client = new ClientDetail();



                UpdateModel(client);
                //Debug Code
                System.Diagnostics.Debug.WriteLine("AddNewClient Create1");
                repo.AddNewClient(client);
                //Debug Code
                System.Diagnostics.Debug.WriteLine("Save Create1");


                // System.Data.SqlClient.SqlException thrown at this line
                repo.Save();

                //Debug Code - never reached
                System.Diagnostics.Debug.WriteLine("Saved Changes");


              //  return RedirectToAction("Details", new { id = client.ClientNo });




            }
            return View(client);
        }

public void AddNewClient(ClientDetail client)
       {
            System.Diagnostics.Debug.WriteLine("Start Insert On Submit");

            db.ClientDetails.InsertOnSubmit(client);
            System.Diagnostics.Debug.WriteLine("Finish Insert On Submit");
       }

public void Save()
        {
            System.Diagnostics.Debug.WriteLine("In Save Method");
            db.GetChangeSet();
            System.Diagnostics.Debug.WriteLine("Got ChangeSet");
            db.SubmitChanges();
            System.Diagnostics.Debug.WriteLine("Exit Save Method");
        }
Is this the query everyone is talking about

[Column(Storage="_ClientNo", DbType="Int NOT NULL", IsPrimaryKey=true, UpdateCheck=UpdateCheck.Never)]
        public int ClientNo
        {
            get
            {
                return this._ClientNo;
            }
            set
            {
                if ((this._ClientNo != value))
                {
                    this.OnClientNoChanging(value);
                    this.SendPropertyChanging();
                    this._ClientNo = value;
                    this.SendPropertyChanged("ClientNo");
                    this.OnClientNoChanged();
                }
            }
        }

有谁知道一个解决方案或理由,为什么这是发生?

Does anyone know a solution or reason as to why this is occuring?

感谢您

推荐答案

添加IsDbGenerated = true要ClientNo地产

Add IsDbGenerated=true To ClientNo Property

[Column(Storage="_ClientNo", DbType="Int NOT NULL", **IsDbGenerated=true,** IsPrimaryKey=true, UpdateCheck=UpdateCheck.Never)]
public int ClientNo

这篇关于当IDENTITY_INSERT设置为OFF表不能为标识列插入显式值'ClientDetails“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 08:05