SQL Server and C#: get last inserted id

前端 未结 9 1060
执念已碎
执念已碎 2020-12-10 02:18
public static void CreateSocialGroup(string FBUID)
{
    string query = \"INSERT INTO SocialGroup (created_by_fbuid) VALUES (@FBUID); SELECT @@IDENTITY AS LastID\";
         


        
9条回答
  •  悲哀的现实
    2020-12-10 02:39

    You can use ExecuteScalar to get the last value from a Sqlcommand.

    The scope_identity() function is safer than @@identity.

提交回复
热议问题