ASP.NET TIPS: Get the ID of the recorded record

xiaoxiao2021-04-01  236

Your SQL Statement String Sqlstr = @ "Insert Into Table (...) VALUES (...) Select Scope_identity () AS 'MyNewID'"; Execute SqlsqlDataReader MyDR = Execute your SQL statement with an ExecuteReader method to get IDMYDR.GetValue (0) .Tostring () Note: / * For the IDETENT_CURRENT ('TBNAME') * / INSERT INTO TABLE (Field1, Field2, ...) VALUES for the last insertion operation you want to get in a table. "FIELD1VALUE", "Field2Value", ...) SELECT IDENT_CURRENT ('RecordID') As newidValue / * For new records that are just inserted immediately with scope_identity () is the most suitable * / Insert Into Table (Field1, Field2 , ...) VALUES ("Field1Value", "Field2Value", ...) SELECT Scope_identity () as newidValue / * is best used for the self-increasing ID you want to get in a series of operations. @@ iDENTITY * / INSERT INTO TABLE (Field1, Field2, ...) Values ​​("Field1Value", "Field2Value", ...) SELECT @@ identity As newidValue

转载请注明原文地址:https://www.9cbs.com/read-131211.html

New Post(0)