c# last insert id

后端 未结 1 1563
南旧
南旧 2021-01-25 07:45

I\'m using a stored procedure with this sql:

INSERT INTO [dbTblUsers]([strUsername], [strPassword])
VALUES (@p1,@p2);
SELECT @@IDENTITY;

And ca

相关标签:
1条回答
  • 2021-01-25 07:58

    Firstly, don't use @@IDENTTY - use SCOPE_IDENTITY(); the first can give you unexpected answers if there are any triggers involved. Secondly; both of these return decimals; cast it at the call-site, IMO:

    SELECT CAST(SCOPE_IDENTITY() as int)
    
    0 讨论(0)
提交回复
热议问题