Edit records of a field clientdataset from a Join

Asked

Viewed 1,215 times

2

I have a simple example, but in three layers, with sqldataset + datasetprovider + clientdataset. I do not load any field in sqldataset. In datasetprovider I leave the updatemode in upwherekeyonly.

In datasetprovider I leave allowcommandtext as true to be able to receive client-side commandtext via clientdataset. On the client side I load the Fields with Select * ... and during the run time I send the commandtext with a Join so that it brings only the fields already loaded. When I try to edit some record and give applyupdates in onreconcileerror event I get:

Unable to Find Record. No Key especified

Use xe5+dbexpress+mysql. The question is how do I configure components to edit and update records coming from a command with Join?

SUMMING UP THE DISCUSSION

You can leave all the default settings of Delphi, the only thing you need is to put in the event Ongettablename of the datasetprovider the name of the table to be updated, this solved all my problems.

1 answer

2


Artur, this happens because for Dataset understands that all fields belong to the same table.

To fix the problem, you must configure which fields are not table data fields, which key and which table to update.

Properly configure the fields

One way to do this is by setting the property Providerflags to empty, saying that the field should not appear either in the Where nor be updated (pfInWhere, pfInUpdate).

CampoA.ProviderFlags := [];

Or by changing the Fieldkind for fkInternalCalc.

CampoA.FieldKind := fkInternalCalc;

Another important thing is to define the primary key field, to ensure that the Precedent correctly identifies the key to be used, and for this you must set the Providerflag for pfInKey

CampoChave.ProviderFlags := CampoChave.ProviderFlags + [pfInKey];

or Field.Providerflags := [pfInUpdate, pfInKey];

Set the name of the table to be updated

In addition, it is recommended to implement the event onGetTableName of Tdatasetprovider, so that he knows which table to update.

procedure DataSetProvider.onGetTableName(Sender: TObject);
begin
    Result := 'NomeDaTabelaASerAtualizada';
end;
  • @Capauto thanks for the reply when arrive on pc I return you. Just remembering, as I said above, in my Internet I don’t bring fields from another table, only from one, I do like two filtering in a table, master/detail.

  • In this case ignore the portion of taking fields from update and Where, just change the key field and set the table name. It’s been a long time since I’ve touched datasets but if I remember correctly we did so. Anything only notifies here that I can help more if you don’t solve.

  • worked out, really the problem was not having the ongettable event the table name, thank you very much!

  • now the problem is that it does not edit or delete, but saves, it appears: Unable to find record. No key specified.

  • I managed to solve, I put instead of upwherekeyonly, upwhereall. Many thanks again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.