You can use the INSERT statement instead of opening a dataset. Here is a code example:
Code: Select all
Q1.SQL.Text := 'INSERT INTO `MyTable` ... ';
Q1.ParamByName('first_param').AsInteger := 1;
Q1.ParamByName('second_param').AsString := 'test';
Q1.Execute;
To increase performance, you can prepare the INSERT statement. Here is a code example:
Code: Select all
Q1.SQL.Text := 'INSERT INTO `MyTable` ... ';
Q1.Prepare;
for i := 1 to 10 do begin
Q1.ParamByName('first_param').AsInteger := i;
Q1.ParamByName('second_param').AsString := 'test';
Q1.Execute;
end;
Also, you can use the TMyLoader component that serves for fast loading of data to the server. TMyLoader work is based on generation of INSERT statements that insert data by several rows at once (you can control it using the TMyLoader.RowsPerQuery property). For more information about TMyLoader, please read the MyDAC documentation.