无法将数据插入带有标识列的表中 [英] Cannot INSERT data into table with identity column
问题描述
在我的程序中,我有一个EmployeeRegistry表,该表保存每个员工的工作出勤率数据.每个出席记录都由一个名为"AttendanceID"的IDENTITY列来唯一区分,该IDENTITY SEED为1,IDENTITY增量为1.但是,当我尝试通过VB.NET程序将一个出席记录插入到表中时.它给出一个错误说:
仅在使用列列表且IDENTITY_INSERT为ON时,才能为表EmployeeEmployeey中的身份列指定一个显式值."我试图通过SQL Management Studio使用SQL查询将数据插入表中,并且它没有问题地插入了数据.可能是什么问题?
In my program I have an EmployeeRegistry table which holds data of each employee''s work attendance. Every attendance record is uniquely distinguished by an IDENTITY COLUMN called "AttendanceID" which has an IDENTITY SEED of 1 and an IDENTITY increment of 1. However when I try to insert an attendance record to the table via my VB.NET program. it gives an error saying:
"An explicit value for the identity column in table ''EmployeeRegistry'' can only be specified when a column list is used and IDENTITY_INSERT is ON." I tried to insert data into the table using an SQL query via the SQL management studio and it inserted the data without a problem. What might be wrong?
推荐答案
听起来像是在标识列中插入值.不要为该列提供价值.然后再次验证身份增量& 身份种子值.
执行以下语句
Sounds like you are inserting values to the identity column. Don''t give value for that column. Then verify again Identity increment & Identity Seed values.
execute the following statement
SET IDENTITY_INSERT table_name ON
然后重试
then retry
错误是该错误说明.您编写了指定身份值(自动生成身份值)的代码.编辑您的帖子并发布一些代码,如果需要更多具体帮助.
What''s wrong is what the error says. You wrote code that specifies the identity value, when it is auto generated. Edit your post and post some code if you need more specific help.
您是否不小心尝试将数据插入键列?
在这种情况下,请不要在身份列中插入任何内容,其余的查询应该可以正常工作.
Are you accidentally trying to insert data into the key column?
In such a case, do not insert anything into the identity column and the rest of query should work fine.
这篇关于无法将数据插入带有标识列的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!