Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Cannot insert explicit value for identity column in table 'Producto' when IDENTITY_INSERT is set to OFF.
alter proc uspIdatos_
@iDProducto int output,
@Descripcion nvarchar(50),
@Precio money,
@Stock int,
@Notas text
as
Insert into Producto(IDProducto,Descripcion,Precio,Stock,Notas)values(@iDProducto,@Descripcion,@Precio,@Stock,@Notas)
SET @iDProducto=@@IDENTITY
Posted
Comments
joshrduncan2012 22-Aug-14 13:49pm    
So, what's the question?

No, you can't.

But...if you declared @iDProducto as an INPUT value rather than an OUTPUT, perhaps you could...but then you couldn't return it.

So make your mind up: either this is an identity field, SQL should manage it, and you should return it; or it isn't, it is specified from outside, and so there is no need to return it.
 
Share this answer
 
You can use this command before your insert command.
SQL
SET IDENTITY_INSERT dbo.Producto ON;
 
Share this answer
 
v2
SQL
alter proc uspIdatos_
 @iDProducto int output,
 @Descripcion nvarchar(50),
 @Precio money,
 @Stock int,
 @Notas text
 as

SET IDENTITY_INSERT Producto ON;

 Insert into Producto(IDProducto,Descripcion,Precio,Stock,Notas)values(@iDProducto,@Descripcion,@Precio,@Stock,@Notas)
 SET @iDProducto=@@IDENTITY 

SET IDENTITY_INSERT Producto OFF;
 
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