如何在表sql server c#中获取最后插入的值
问题描述:
我想在表ProjectGroup中获取最后插入的groupID
这是表格
ProjectGroup
* GroupID
* GroupName
* ProjectName
I want to get the last inserted groupID int the table ProjectGroup
Here is the table
ProjectGroup
*GroupID
*GroupName
*ProjectName
答
Refer :
1. get-the -last-inserted-row-id-with-sql-statement [ ^ ]
2. 获取插入行标识的最佳方法是什么? [ ^ ]
3. SQL服务器-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record / [ ^ ]
Refer:
1. get-the-last-inserted-row-id-with-sql-statement[^]
2. Best way to get identity of inserted row?[^]
3. sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/[^]
这里是SQL:
here's the SQL:
SELECT TOP(1) GroupID FROM ProjectGroup ORDER BY 1 DESC
如果您需要使用ADO或Linq的C#代码,请告诉我
let me know if you need any code in C# using ADO or Linq
您提供了列列表,b没有任何数据类型或用法的指示。
GroupId是一个身份字段,当插入记录时会自动增加吗?
如果在这种情况下,然后选择具有最大组ID的记录。
但是,如果组ID可以按任何顺序插入,那么你需要有表示插入顺序的字段,例如插入日期。在这种情况下,您可以使用最大插入日期。
You have provided a list of columns, but no indication of the data type or usage.
Is the GroupId an identity field that automatically increases when a record is inserted?
If that is the case, then select the record with the maximum group id.
If, however, the group id can be inserted in any order, then you need to have a field that indicates the insertion order, such as insertion date. In this scenario, you can use the maximum insertion date.