Skip to content
Advertisement

Increasing the number of ids in the TextBox by one

I have a table in my Sql Server and I have a value in this table.
Table name = veriler
Values name= Project ID int(PRIMARY KEY)

I’m doing project automation for electrical engineer’s project.
If engineer click the new project button. My program redirect to the Genel.aspx page.

When the new project is opened, I want my id number to be pulled from the table and incremented by one and written to the textbox.
I don’t know at what stage I should do this.

I especially want help on this topic. At what stage should I increase the ID number one by one? When opening the Genel.aspx page or saving the project in the data table and I have no idea how to increase it.

ProjeID textbox in Genel.aspx page
Sql Table
Genel.aspx on web page

I am using the Dev Express textbox(ASP.NET WEB Application(.Net Framework))

Advertisement

Answer

Well as it is the ID field, so I recommend instead of doing this manually, just making the ID as IDENTITY field:

ID int IDENTITY(1,1) PRIMARY KEY

this way the ID will automatically be increased every time a new record is added. (read more about IDENTITY HERE) and then when inserting a new record, you can get the last inserted id with @@IDENTITY

like:

INSERT INTO PROJECTS (...) values(...); SELECT @@IDENTITY

however if you want to do this manually, you can get the MAX(Id) of and increase it manually

SELECT MAX(ID) FROM PROJECTS

I don’t recommend the second one at all because it can cause problems. for instance, lets say you got the MAX and increased it, and before you insert it, someone from somewhere else adds a new project, now when you are adding a project with MAX(ID)+1 it already exists.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement