Recent

Author Topic: [SOLVED] How to append records to a MSAccess database table?  (Read 1685 times)

dkjMusic

  • Full Member
  • ***
  • Posts: 146
[SOLVED] How to append records to a MSAccess database table?
« on: August 27, 2014, 03:51:06 am »
Can someone steer me to an example?

Thanks.
« Last Edit: August 31, 2014, 10:11:16 am by dkjMusic »
Windows 7 Ultimate/32 bit;
Lazarus 0.9.31/Rev 33300;
FPC 2.7.1/Rev 19464;
GDB 7.0.50;
(via CodeTyphon 2.30)

minesadorada

  • Sr. Member
  • ****
  • Posts: 452
  • Retired
Re: How to append records to a MSAccess database table?
« Reply #1 on: August 27, 2014, 08:39:00 am »
This example code snippet works for most SQL-based databases - including MSAccess.   It's not 'model code' but it works for me.
Code: [Select]
sz := 'INSERT INTO ' + fUserTableName + ' ';
sz += '(name1,name2,name3,birthyear,height,heightunit)';
sz += ' VALUES (''%s'',''%s'',''%s'',''%d'',''%d'',''%d'')';
sz := Format(sz, [fUsername1, fUsername2, fUsername3, fUserBirthYear,
  fUserHeight, fUserHeightUnit]);
SQLQuery.SQL.Text := sz;
  Try
    Try
    SQLQuery.ExecSQL;
    SQLTransaction.CommitRetaining;
    Except
    on e: Exception Do
      SQLTransaction.RollbackRetaining;
    End;
  Finally
  SQLTransaction.EndTransaction;
  End;
GPL Apps: Health MonitorRetro Ski Run
OnlinePackageManager Components: LazAutoUpdate, LongTimer, PoweredBy, ScrollText, PlaySound, CryptINI

 

TinyPortal © 2005-2018