Tech Story

Menu
  • Home
  • Programing
    • Delphi
      • Database
    • Arduino
    • Android
    • Unix Socket
    • Database
  • Network
    • Mikrotik
  • Computer
  • software
    • File Recovery
    • Driver software
    • backup
    • download
    • Drivers
    • format converter
    • programing tools
    • internet
    • phone apps
    • Network
    • graphics
    • professional
    • DISK AND PARTITION
    • OPTIMIZER
    • utility
    • programming tools
    • Games
      • android games
      • computer games
      • ps4
  • Digital Coin
    • Bitcoin
    • Blockchain
  • Privacy Policy
  • contact us
  • news
  • Series and Movies
  • YouTube watch
  • Blog
    • Computer
    • Network
    • General
    • Health and Fitness
    • Management skills
    • Monuments
    • electrical and electronics
Home
Programing
Delphi
Database
Recover the ID of the last inserted row in a table (ADO)
Programing

Recover the ID of the last inserted row in a table (ADO)

July 20, 2020

// Insert a new Record…

var
  LastID: Integer;
//  Query: TADOQuery;
//  oder
//  Query: TQuery;
begin
  Query.Active := False;
  Query.SQL.Clear;
  Query.SQL.Append('INSERT INTO Table (Spalte) VALUES (Value)');
  Query.ExecSQL;
  LastID := GetLastID(Query);
end;

// get the ID of the last inserted row
function GetLastID(var Query: TADOQuery {or TQuery}): Integer;
begin
  result := -1;
  try
    Query.SQL.clear;
    Query.SQL.Add('SELECT @@IDENTITY');
    Query.Active := True;
    Query.First;
    result := Query.Fields.Fields[0].AsInteger;
  finally
    Query.Active := False;
    Query.SQL.clear;
  end;
end;
Share
Tweet
Email
Prev Article
Next Article

Related Articles

XML format is primarily used for exchange of data in …

Crystal Reports – Data Export To XML

// Search a directory tree for a specified file uses …

Search a directory tree for a specified file in delphi

Recent Posts

  • Change the function of the Fn key on Windows and Mac laptops
  • Hard drive not detected on Lenovo and Asus laptops
  • How to Merge Multiple PDF Files (PDF)
  • Restore virtual machine files and virtual disks
  • Troubleshooting your virus and threat protection is managed by your organization

Categories

  • Advertisement
  • Android
  • android games
  • antivirus
  • Arduino
  • audio video editor
  • backup
  • Bitcoin
  • Blockchain
  • Blog
  • Chinese medicine
  • Computer
  • Computer
  • computer games
  • Database
  • Database
  • Delphi
  • DISK AND PARTITION
  • download
  • Driver software
  • Drivers
  • electrical and electronics
  • Fashion and beauty
  • File Recovery
  • Forex Trading
  • format converter
  • General
  • general
  • graphics
  • Health and Fitness
  • Healthy Eating
  • internet
  • Management skills
  • Mikrotik
  • Monuments
  • Network
  • Network
  • News
  • Nutrition
  • Operating System
  • OPTIMIZER
  • passwords
  • phone apps
  • phone software
  • professional
  • Programing
  • programing tools
  • programming tools
  • ps4
  • Raspberry Pi
  • Series and Movies
  • software
  • Sport
  • thems
  • Uncategorized
  • Unix Socket
  • utility
  • Videos
  • YouTube watch

Tech Story

Copyright © 2021 Tech Story
Theme by MyThemeShop.com

Ad Blocker Detected

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Refresh