Why is this throwing a primary key violation!!?!?



Morning all...

I'm scratching my head to find out why this is throwing a primary key violation.

aTables is an Array of type Tadoquery.

What happens is qryJobInfo is the "Header" of a log, and the qryJobTasks is the detail lines. I save the header, grab the job number and then pass it to the query to save the detail lines.

It works great when I create a brand new job and add 3 or 4 detail lines, but whenever I create a job, save it and go back to modify it it throws a PK violation.

Josh



procedure TdmLogInfo.SaveJob;
var
  i: smallint;
begin
  dmCustomer.SaveCustomer;

dmShippingAssumptions.SaveAss(qryJobInfo.FieldByName('CustomerID').AsInteger);
dmGlobal.conGlobal.BeginTrans;
try
// Grabs the Customer ID and makes sure the Job Customer ID = the Open Customer


qryJobInfo.FieldByName('CustomerID').Value := dmCustomer.qryGetCustomer.FieldByName('CustomerID').value;

    if qryJobInfo.State in [dsEdit, dsInsert] then qryJobInfo.Post;
    qryJobInfo.UpdateBatch(arAll);


for i := 1 to high(aTables) do begin // Violation gets thrown //around here
with aTables[i] do begin
first;
while not EOF do begin
Edit;
FieldByName('JobNo').AsInteger := JobNo;
Post;
Next;
end;
UpdateBatch(arAll);
end;
end;
dmGlobal.conGlobal.CommitTrans;
except
dmGlobal.conGlobal.RollbackTrans;
end;
end;
.