用FireDAC在access数据库中添加一行数据,此处利用的是SQL语句插入方法
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); {这样也是可行的}
myConn.Close();
myConn.Free();
end;
以下的方法也行
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;