给你参考
下面是我用线程一次性加如全部记录。你完全可以仿照我下面的做法。
分段你自己控制一下就可以了。
uses activex;
private
Procedure AddDataToDB;
public
end;
TTimerThread = class(TThread)
procedure Execute;
override;
end;
var
form1: Tform1;
Thread1:TTimerThread;
implementation;
procedure TTimerThread.Execute;
begin
Priority := tpNormal;
freeonterminate:=true;
CoInitialize(Nil);
try
form1.AddDataToDB;
finally
CoUninitialize;
end;
end;
Procedure tform1.AddDataToDB;
var i:integer;
begin
With clientdataset2do
begin
close;
commandtext:='select * from table where 1=2';
open;
clientdataset1.first;
for i=1 to clientdataset1.recordcountdo
begin
append;
fieldbyname('field1').asstring:=clientdataset1.fieldbyname('filed1').asstring;
fieldbyname('field2').asstring:=clientdataset1.fieldbyname('filed2').asstring;
....
post;
clientdataset1.next;
end;
clientdataset2.ApplyUpdates(-1);//这句话会把20000记录 一次性的保存到数据库
end;
end;
Procedure tform1.button1Onclick(Sender: TObject);
begin
Thread1:=TTimerThread.Create(false);
end;