Hi,
I have a volatile child table that needs all the child records deleting and then re-inserting a new batch, some of which may be the same as those that were deleted. I tried the following code:
// delete all existing keywords
while tbl.recordcount > 0 do tbl.delete;
// (A)
// now insert the new keywords
for i := 0 to KeywordList.Count-1 do
begin
tbl.insert;
tbl.ParentID := ID;
tbl.Keyword := KeywordList.strings[i];#
tbl.Post;
end;
tbl.ApplyUpdates;
The tbl is a TDAMemDataTable, the sql table itself has just the two fields ParentID & Keyword which together form the primary key.
I would’ve thought that the above code would delete the existing records then insert the new ones in a batch, but I get numerous Primary Key violation errors ?
If I add “tbl.ApplyUpdates” at (A) above, then the problem goes away.
Is this an RO/DA bug? If not, how to I delete and re-insert in a transaction?
Cheers
Delphi 10.1 Berlin
RO/DA 9.0.97.1245
SQL Server 2008 R2 using FireDAC