Add a row of data to an Access database with FIREDAC, using the SQL statement insertion method
Procedure Tform1.btninsertdataclick (Sender:tobject);
Var
Mycom:tfdcommand;
Myqry:tfdquery;
Myconn:tfdconnection;
sql:string;
Begin
sql: = ' Insert into tpusers (username,userpwd) VALUES (' 10795 ', ' xx ') ';
MyConn: = Tfdconnection.create (nil);
MyConn.Params.DriverID: = ' MSACC ';
MyConn.Params.Database: = ' D:\TestDelphi\Test2015.mdb ';
Myconn.loginprompt: = false;
MyConn.Open ();
Mycom: = Tfdcommand.create (nil);
Mycom.connection: = myconn;
MyCom.CommandText.Clear ();
MYCOM.COMMANDTEXT.ADD (SQL);
Mycom.execute ();
Myconn.execsql (SQL); {This is also possible}
Myconn.close ();
Myconn.free ();
End
The following methods are also OK
Procedure Tform2.btntestclick (Sender:tobject);
Const
Strinsert = ' Insert into Tpusers (username,userpwd) VALUES (: name,:age) ';
Var
I:integer;
Begin
Con1. Params.driverid: = ' MSACC ';
Con1. Params.database: = ' D:\Test2015.mdb ';
Con1. Loginprompt: = false;
Con1. Open ();
Con1. Execsql (strinsert,[' AAA ', ' 111 ');
Con1. Execsql (strinsert,[' BBB ', ' 222 ');
Con1. Execsql (strinsert,[' CCC ', ' 333 ']);
Con1. Execsql (strinsert,[' ddd ', ' 444 ');
Con1. Execsql (strinsert,[' eee ', ' 555 ');
Con1. Execsql (strinsert,[' fff ', ' 666 ']);
Con1. Execsql (strinsert,[' ggg ', ' 777 ']);
End
The FireDAC of Delphi Learning