如何在表sql server c#中获取最后插入的值 [英] How To get last inserted value in the table sql server c#

查看:137
本文介绍了如何在表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. <啊REF = http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/> 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.


这篇关于如何在表sql server c#中获取最后插入的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆