SDAC

TCustomMSDataSet.LastInsertId Property

Class

TCustomMSDataSet

Syntax

property LastInsertId: Int64;

Remarks

The last identity value is generated in any table in the current session. The function @@IDENTITY is used to identify the last-inserted identity value. To get the value, it's required to run an adiitional request to the server.

Example

To prevent an additional request, it's recommended to generate the identifier value

MSQuery1.SQL.Clear;
MSQuery1.SQL.Add('INSERT INTO Dept (dname, loc) VALUES (:dname, :loc)');
MSQuery1.SQL.Add('SET :Identity = SCOPE_IDENTITY()');
MSQuery1.ParamByName('Identity').ParamType := ptOutput;
MSQuery1.ParamByName('dname').AsString := 'ACCOUNTING';
MSQuery1.ParamByName('loc').AsString := 'NEW YORK';
MSQuery1.Execute;

id := MSQuery1.ParamByName('Identity').AsInteger; 
© 1997-2024 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback