I have an ADOQuery that inserts a record to SQL Server 2005 table that has trigger inserting data to another table. I use following code to refresh the query and avoid Row cannot be located for updating
(There are PKs on each table, UpdateCriteria property are set, Cursors are set to Dynamic, yet I still get the error sometimes. However it's not the question now).
procedure Requery(T: TCustomADODataSet; IDField: string);
var
i: integer;
begin
if T.RecordCount > 0 then
i := T.FieldByName(IDField).AsInteger;
T.Requery();
if T.RecordCount > 0 then
T.Locate(IDField, i, []);
end;
Before requery, I can get value of ID field. However, after requery, ID field returns value of ID field of the other table record insterted by trigger. Both tables has ID field with same name. I have also added SET NOCOUNT ON .... OFF
to trigger to avoid Too Many Rows Affected
error, however I don't think this affects my problem. I haven't seen errors like these when I was working with Delphi 6 - 7 and SQL Server 2000, hence I'm willing to give SDAC or DAO a try. Would SDAC or DAO solve the problem or is there any solution without changing the ADOQuery?