Hello Friends!
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,
@cat_idl2 INT,
@title NVARCHAR(50),
@description NVARCHAR(300),
@details TEXT,
@MetaKeywords NVARCHAR(200),
@Inactive BIT,
@Userid INT
)
AS
BEGIN
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)
VALUES
(@ArticleId, @Userid, @cat_idl2, @title, @description, @details,@MetaKeywords, @Inactive)
END
Please friends explain its reason and solution. Waiting for your guidance.
Thanks