Click here to Skip to main content
16,017,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

Can you please with the error below?

An explicit value for the identity column in table 'tblreg' can only be specified when a column list is used and IDENTITY_INSERT is ON.


Thanks for your help.
Posted

Its indicating you are trying to insert a value in a colunm which is declared as an Identity colunm.

Have a look at below link to understand Identity.
http://en.wikipedia.org/wiki/Identity_column

http://www.sqlteam.com/article/understanding-identity-columns

Solution :- Either do not specify value in your Insert statement for the colunm which is declared as an Identity colunm. Or incase if you want to continue with explicit value then have a look at below link to resolve your issue.
http://blog.sqlauthority.com/2007/03/28/sql-server-fix-error-8101-an-explicit-value-for-the-identity-column-in-table-can-only-be-specified-when-a-column-list-is-used-and-identity_insert-is-on/
 
Share this answer
 
If you declare a column as Identity = true, then SQL will handle the values and will assign them sequentially so that you cannot get repeats. If you try at any time to set the value of that field via an INSERT or UPDATE operation, SQL will throw that exception.

The most common mistake is to try and do an "anonymous" INSERT operation:
C#
INSERT INTO MyTable VALUES (1, 2, 3)
Where the first column in the table is the ID column, declared as identity. SQL tries to assign such inserts in numerical column order, and so tries to write the first value into the Identity field. USe names columns at all times and you won't get the problem:
SQL
INSERT INTO MyTable (ProdCount, ItemNo, Bananas) VALUES (1, 2, 3)
 
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