Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to solve this error, i am developing billing s/w here i am using identity for bill number. But error is came how to solve this error Any one guide me.

Cannot insert explicit value for identity column in table 'bill' when IDENTITY_INSERT is set to OFF.

This is for my SQL Query

SET IDENTITY_INSERT bill ON insert into bill(staffid,cstid,cstname,schemes,counum,recnum,date,slno,proname,price,qty,protax,dis,amt)values(@staffid,@cstid,@cstname,@schemes,@counum,@recnum,@date,@slno,@proname,@price,@qty,@protax,@dis,@amt)SET IDENTITY_INSERT bill OFF

What I have tried:

Cannot insert explicit value for identity column in table 'bill' when IDENTITY_INSERT is set to OFF.
Posted
Updated 1-Aug-16 7:35am
Comments
José Amílcar Casimiro 1-Aug-16 11:38am    
What is the bill table schema? dbo?
Richard Deeming 1-Aug-16 12:57pm    
If you need to use SET IDENTITY_INSERT for anything other than occasional maintenance tasks, then your table design is wrong.

Either change your table so that the column is not an identity column; or change your query so that you're not trying to insert a value into that column.

1 solution

You could try:
SQL
ALTER TABLE YourTableName NOCHECK CONSTRAINT YourConstraint

See: SQL SERVER - How to Disable and Enable All Constraint for Table and Database - Journey to SQL Authority with Pinal Dave[^]
 
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