首先设置AQmain datasource1
AQDetail Datasource2
AQDetail.datasource := Datasource1
AQDetail.locktype := ltBatchOptimistic
procedure TForm1.FormCreate(Sender: TObject);
begin
if not AQMain.active then AQMain.open;
if not AQDetail.Active then AQDetail.Open;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
AQMain.Post;
end;
procedure TForm1.AQMainAfterPost(DataSet: TDataSet);
begin
AQDetail.UpdateBatch();
AQDetail.DataSource := DataSource1 ;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AQMain.Append ;
AQMain.FieldByName(''Adate'').value := datetostr(date());
end;
procedure TForm1.AQMainAfterInsert(DataSet: TDataSet);
begin
AQDetail.DataSource := nil;
end;
procedure TForm1.AQDetailAfterInsert(DataSet: TDataSet);
begin
AQDetail.FieldByName(''mgrno'').value:=AQMain.FieldByName(''mgrno'').value;
end;