I am working on an asp.net website. I am trying to insert articles in DB on the basis of articleid. For that purpose i have set articleid as primary key in my database table. I have also set Identity specification. However, after setting Identity specification to yes my data is not inserting in DB. It is throwing an Sqlexception with error message
"Cannot insert explicit value for identity column in table 'UserArticleDetails2' when IDENTITY_INSERT is set to OFF"
Following is its stored procedure.
ALTER PROCEDURE [dbo].[Proc_UserArticleDetails_AddNew]
@ArticleId INT OUTPUT,
SET @ArticleId = ISNULL((SELECT MAX(@ArticleId) + 1 FROM UserArticleDetails2 WITH (NOLOCK)),1)
IF @ArticleId IS NULL
SET @ArticleId = 1
INSERT INTO [UserArticleDetails2]
(ArticleId,Userid, cat_idl2, title, description, details,MetaKeywords, Inactive)
(@ArticleId, @Userid, @cat_idl2, @title, @description, @details,@MetaKeywords, @Inactive)
Please friends explain its reason and solution. Waiting for your guidance.