Sell_QY(主表控件用的是adoquery),SellChild_QY(从表控件用的是ADODataSet). sell_qy和sellchild_qy的locktype属性都设为ltBatchOptimistic. SellChild_QY的TParameters添加了一个CONID Sell_QY.sql.Add('select * from sell_tb order by autoid'); SellChild_QY.commandtext:='select * from sellchild_tb where conid=:conid'; 主表的CONID字段是自动编号的,与从表的CONID字段相关联 //--------------------------------------------- procedure TDM_FM.SellChild_QYAfterInsert(DataSet: TDataSet); begin if sell_qy.State in [dsinsert,dsedit] then sell_qy.Post; end;procedure TDM_FM.SellChild_QYNewRecord(DataSet: TDataSet); begin SellChild_QY.FieldByName('Conid').Value:= SellChild_QY.Parameters[0].Value; end;procedure TDM_FM.Sell_QYAfterScroll(DataSet: TDataSet); begin SellChild_QY.Parameters[0].Value := Sell_QY.FieldByName('conid').AsInteger; end;按照ypnet(高原)所说的加了一条 procedure TDM_FM.Sell_QYAfterPost(DataSet: TDataSet); begin SellChild_QY.UpdateBatch(arall); end; 现在的情况是可以保存进去了,但关联字段没有与主表关联上 保存语句: SellChild_QY.UpdateBatch; Sell_QY.UpdateBatch;
ADODataSetMaster.UpdateBatch(arAll);
ADODataSetDeatil.UpdateBatch(arAll);記住,最好在添加從表前,把主表Post。
ADODataSetDeatil.UpdateBatch(arAll);
sell_qy和sellchild_qy的locktype属性都设为ltBatchOptimistic.
SellChild_QY的TParameters添加了一个CONID
Sell_QY.sql.Add('select * from sell_tb order by autoid');
SellChild_QY.commandtext:='select * from sellchild_tb where conid=:conid';
主表的CONID字段是自动编号的,与从表的CONID字段相关联
//---------------------------------------------
procedure TDM_FM.SellChild_QYAfterInsert(DataSet: TDataSet);
begin
if sell_qy.State in [dsinsert,dsedit] then sell_qy.Post;
end;procedure TDM_FM.SellChild_QYNewRecord(DataSet: TDataSet);
begin
SellChild_QY.FieldByName('Conid').Value:= SellChild_QY.Parameters[0].Value;
end;procedure TDM_FM.Sell_QYAfterScroll(DataSet: TDataSet);
begin
SellChild_QY.Parameters[0].Value := Sell_QY.FieldByName('conid').AsInteger;
end;按照ypnet(高原)所说的加了一条
procedure TDM_FM.Sell_QYAfterPost(DataSet: TDataSet);
begin
SellChild_QY.UpdateBatch(arall);
end;
现在的情况是可以保存进去了,但关联字段没有与主表关联上
保存语句:
SellChild_QY.UpdateBatch;
Sell_QY.UpdateBatch;
能详细的说一下吗?事务我不懂的