简体   繁体   English

将 TextBox 中的 ID 数量增加一个

[英]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.我的 Sql 服务器中有一张表,我在这张表中有一个值。
Table name = veriler表名 = veriler
Values name= Project ID int(PRIMARY KEY)值 name= 项目 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.我的程序重定向到 Genel.aspx 页面。

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.打开新项目时,我希望从表中提取我的 ID 号并加一并写入文本框。
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.打开genel.aspx页面或者保存工程到data.table时不知道怎么增加。

ProjeID textbox in Genel.aspx page Genel.aspx 页面中的 ProjeID 文本框
Sql Table Sql表
Genel.aspx on web page web 页面上的 Genel.aspx

I am using the Dev Express textbox(ASP.NET WEB Application(.Net Framework))我正在使用 Dev Express 文本框(ASP.NET WEB Application(.Net Framework))

Well as it is the ID field, so I recommend instead of doing this manually, just making the ID as IDENTITY field:因为它是 ID 字段,所以我建议不要手动执行此操作,只需将 ID 作为 IDENTITY 字段:

ID int IDENTITY(1,1) PRIMARY KEY

this way the ID will automatically be increased every time a new record is added.这样,每次添加新记录时,ID 都会自动增加。 ( read more about IDENTITY HERE ) and then when inserting a new record, you can get the last inserted id with @@IDENTITY 在此处阅读有关 IDENTITY的更多信息)然后在插入新记录时,您可以使用@@IDENTITY获取最后插入的 ID

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但是,如果您想手动执行此操作,您可以获取MAX(Id)并手动增加它

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.例如,假设您获得了 MAX 并增加了它,并且在您插入它之前,其他地方的人添加了一个新项目,现在当您添加一个带有MAX(ID)+1的项目时,它已经存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM