Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a requirement where if a user creates a new form, the ID value should increment autoamtically. I used SQL to do it. Below is my code:

string strcomm = string.format(@"IF EXISTS(select * from [DATABASE].[TABLE] where ID is NULL and [ArtifactID] = @ArtifactID)
Begin
update [DATABASE].[TABLE] SET [ID]= (Select CAST(MAX(ISNULL(ID,0)) as int)+1 from [DATABASE].[TABLE]) where [ArtifactID] = @ArtifactID
END");

The problem is, whenever user creates a task, it is incrementing the value but, it is incrementing only till 10. Whatever the task created after 10, it is taking the value as 10 only. Can anyone help me over this?

What I have tried:

I am new to SQL and tried changing but didn't get. Any help would be appreciated.
Posted
Updated 8-Jul-16 18:09pm
Comments
Member 8010354 8-Jul-16 4:49am    
Can anyone help me on this how to resolve?

This solution may be help you

At the time of create table

create table tablename
(
id int not null identity(1,1) primary key
)
 
Share this answer
 
SQL
CREATE TABLE (
  ID_column INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
  ...
);


IDENTITY property will auto-increment the column up from number 1.
 
Share this answer
 
 
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