Click here to Skip to main content
15,891,852 members
Please Sign up or sign in to vote.
4.33/5 (2 votes)
See more:
I have got three columns.

When I passed the query like this, it is showing the error:
Cannot insert explicit value for identity column in table 'tblcharge22' when IDENTITY_INSERT is set to OFF.
I am trying to insert into tbltt(srno,txn,ppt) values (1,1,1)
Posted
Updated 13-Apr-11 21:28pm
v2
Comments
Dalek Dave 14-Apr-11 3:28am    
Edited for Grammar and Readability.

Have a look at these discussions and resolution suggested:
Link 1[^]
Link 2[^]
Link 3[^]

Google[^] has more info in case needed.
 
Share this answer
 
try this


SQL
SET IDENTITY_INSERT TableName  On
insert into TableName  Values(1,1,1)
SET IDENTITY_INSERT TableName  OFF
 
Share this answer
 
Comments
Dalek Dave 14-Apr-11 3:29am    
Looks good.
Unless you have a verry good reason: don't insert an identity!

So just use:
insert into tbltt(txn,ppt) values (1,1)
 
Share this answer
 
Comments
Dalek Dave 14-Apr-11 3:29am    
Good Answer.
MXZ-RXP 19-Dec-13 20:10pm    
thanks! that was the answer-
This will fix it
SQL
SET IDENTITY_INSERT tbltt ON
insert into tbltt(srno,txn,ppt) values (1,1,1) 
SET IDENTITY_INSERT tbltt OFF
 
Share this answer
 
Comments
taher ahmed choudhury 14-Apr-11 1:54am    
still showing error
Costica U 14-Apr-11 1:59am    
What table do you use "tbltt" or "tblcharge22"?
Because the insert uses "tbltt" but the err message is "tblcharge22".

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