The FireDAC of Delphi Learning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.