I am coming across this infamous error in my Delphi application.
In my ADODataSet, I have set my CommandType to cmdText, and then set CommandText to
SELECT * FROM production.details
When I do a record change on my DBGrid, it throws the error of "Unable to find record, no key specified". Under my ClientDataSet, I have set the various fields to have the Provider Flags of [pfInWhere, pfInUpdate, pfInKey], all other fields [pfInWhere, pfInUpdate]
A few people mention that it is the Provider Flags of the ADODataSet that need to be changed, since that is where the query originates. I tried this by the following
ADODataSet.Fields[0].ProviderFlags := [pfInKey, pfInUpdate, pfInWhere];
However, when I do this it throws a different error of List index out of bounds
Eventually I have all this in my DataSourceDataChange procedure:
if mySQLDataModule.dieDetailClientDataSet.ChangeCount > 0 then
begin
dieDetailClientDataSet.FieldByName('die_no').ProviderFlags := [pfInWhere, pfInUpdate, pfInKey];
dieDetailClientDataSet.FieldByName('comment').ProviderFlags := [pfInWhere, pfInUpdate];
dieDetailADODataSet.Fields[0].ProviderFlags := [pfInKey, pfInUpdate, pfInWhere];
dieDetailClientDataSet.ApplyUpdates(0);
end;
More details as requested : this is a MySQL database, the primary key is the same as what is specified in Fields[0]. In the CDS I have already set the ProviderFlags in the Designer Mode. It was because it wasn't working as expected that I read that it has to instead be set in the AdoDataSet as that is where my query has been set, hence me setting it manually here. Because all my fields are set up in the CDS (as there are also calculated fields) for my DBGrid that displays the data, I didn't redo all my fields in the AdoDataSet so there wasn't a designer option there, hence me doing it in code.