voila j'ai fais la transaction ci-dessous, (insertion dans une table maitre et ensuite une table detail)le probleme c'est que je peux inserer le maitre sans le detail et moi je veux pas ça pour garder la cohérence de ma base de données, voilà ma transaction :
with dm.ADOConnection1 do
begin
begintrans;
with dm.InsertMouvementBI do {requete d'insertion table maitre}
begin
Parameters.ParamByName('c1').Value:=strtoint(mvtnum.Text);
Parameters.ParamByName('c2').Value:=strtodate(rzmaskedit1.Text);
Parameters.ParamByName('c3').Value:=strtofloat(rzedit3.text);
Parameters.ParamByName('c4').Value:=strtoint(rzedit4.Text);
Parameters.ParamByName('c5').Value:=strtoint(mvtsor.Text);
Parameters.ParamByName('c6').Value:=rzmemo1.Text;
Parameters.ParamByName('c7').Value:=edit2.Text;
try
ExecProc;
except on E:Exception do
begin
RollbackTrans;
Showmessage(E.Message);
exit;
end;
end;
end;
with dm.InsertDetail_MouvementBI do {requete d'insertion table detail}
begin
for i:=1 to DetailBon.RowCount-1 do
begin
Parameters.ParamByName('c1').Value:=stringgrid1.Cells[1,i];
Parameters.ParamByName('c2').Value:=strtoint(mvtnum.Text);
Parameters.ParamByName('c3').Value:=strtoint(stringgrid1.Cells[4,i]);
Parameters.ParamByName('c4').Value:=strtofloat(stringgrid1.Cells[5,i]);
Parameters.ParamByName('c5').Value:=strtofloat(stringgrid1.Cells[6,i]);
maxdmv.Open;
Parameters.ParamByName('c6').Value:=MAXDMVmaxdmv.Value;
maxdmv.Close;
Parameters.ParamByName('c7').Value:=stringgrid1.Cells[7,i];
try
ExecProc;
except on E:Exception do
begin
RollbackTrans;
Showmessage(E.Message);
exit;
end;
end;
end;
end;
CommitTrans;
end;
merci pour tout vos eclaircissements
Partager