Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?
Posted

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
 
Share this answer
 
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.
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900