I'm trying to edit records from a .DBF database in Delphi 10.1. For this I use ADOQuery.Edit and ADOQuery.Post. I can't figure out, why the following error (translated from german) occurs, after ADOQuery.Post is called:

Error: The line specified for updating was not found. Some values may have been changed since the last read

The editing does take place in an opened second form. The Connection, Datasource and ADOQuery get transfered through properties. The goal is to select a cell in a DBGrid and with the click of an edit button to change the content of the selected cell. My code for editing the records is as following:

  public
    { Public-Deklarationen }
    selectedRow, selectedCol : Integer;
    property ADOConnection : TADOConnection read FADOConnection write FADOConnection;
    property ADOQuery : TADOQuery read FADOQuery write FADOQuery;
    property DataSource : TDataSource read FDataSource Write FDataSource;
  end;
procedure TForm3.DBGrid1CellClick(Column: TColumn);
begin
  selectedCol := DBGrid1.SelectedField.Index;
  selectedRow := DBGrid1.DataSource.DataSet.RecNo;
end;
procedure TForm3.BtnEditClick(Sender: TObject);
var
  iReplacement : string;
begin
  iReplacement := InputBox('Wert', 'Ändere den Wert "' + DBGrid1.Columns[selectedCol].Field.FieldName +  '" für: ' + ADOQuery.Fields[0].AsString + ', ' + ADOQuery.Fields[2].AsString, ADOQuery.Fields[selectedCol].AsString);
  try
    ADOQuery.Edit;
    ADOQuery[DBGrid1.Columns[selectedCol].Field.FieldName] :=  iReplacement;
    ADOQuery.Post;
    //ADOQuery.Refresh;
  except on E: Exception do
    MessageDlg('Error: ' + E.Message, mtError, [mbOk], 0);
  end;
end;

Further info:

connection string of ADOconnection:

Provider=MSDASQL.1;Persist Security Info=False;Extended Properties="CollatingSequence=ASCII;DefaultDir=J:\ROBERT\DATABASE;Deleted=0;Driver={Microsoft dBase-Treiber (*.dbf)};DriverId=277;FIL=dBase IV;FILEDSN=C:\Users\User\Documents\ABzuFA.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Statistics=0;Threads=3;UID=admin;UserCommitSync=Yes;";Initial Catalog=J:\ROBERT\DATABASE

The SQL for opening the database to a DBGrid is:

Select * from Orders

I broke the code done with same result:

ADOQuery1.Edit;
ADOQuery1BEZEICHNG.Value := 'Hello';
ADOQuery1.Post;

Update: I tried on another smaller database and my code works. But sadly I need to make it work for the other too.

0

There are 0 best solutions below