When I do ClientDataset.RefreshRecord, I get a runtime exception
Project DeMijn.exe raised exception class EDatabaseError with message 'Field 'MemberID' cannot be modified'.
The setup is
AdoQuery => DataSetProvider => ClientDataset
I have tried every possible combination of the provider flags on the persistent AdoQuery field, no result:
- I tried it also with the persistent
ClientDatasetfield, no result - In combination, every possible combination, no result
readonly = falseState = dsBrowse
The data provider has ResolveToDataSet true and poPropogateChanges true
I'm using:
- Delphi 12 CE
- SQL Server
MemberIDis an identity column
What magic trick do I need to do a simple RefreshRecord ?
EDIT
The query has a join. The DataProvider has GetTableName set to the correct table
EDIT
I tried removing the field, removing the column from the dbgrid, still the same error.
I am trying out whatever now, desperate why this is not working.
Removing FieldName, setting flags empty, and so on...
Column := ColumnByName(SMDBGridList, PrimaryKeyName);
SMDBGridList.Columns.Delete(Column.Index);
Field := Column.Field;
//Field.FieldName := '';
ggDataModule.ClientDataSetEntity.Fields.Remove(Field);
// field.ProviderFlags := [];
//Field.ReadOnly := false;
//Field.Origin := '';
ggDataModule.ClientDataSetEntity.RefreshRecord;
Edit after debugging
I found that in unit DataSnap.Provider the field is assigned from Delta and there the field is ReadOnly for some reason.
See the code snipet below, from the vcl unit DataSnap.Provider.
In the last line of the code below, Delta.Fields[I].Assign(Field); seems to be a problem.
Field is readonly false but after the Assign it is readonly true because Delta.Fields[I] is readonly
Now this might be a clue, I just don't know how to fix this.
procedure TDataSetProvider.UpdateRecord(Source, Delta: TDataSet; BlobsOnly, KeyOnly: Boolean);
var
Field: TField;
I: Integer;
UseUpMode: TUpdateMode;
DS: TDataSet;
UseFindRecord: Boolean;
begin
if KeyOnly then
UseUpMode := upWhereKeyOnly
else
UseUpMode := UpdateMode;
UseFindRecord := ResolveToDataSet and not Source.IsUniDirectional;
if not UseFindRecord then
DS := TDataSetProvider(Resolver.Provider).GetDataSetFromDelta(
Resolver.UpdateTree, Source, Delta, UseUpMode)
else
begin
if not FindRecord(Source, Delta, UseUpMode) then
DatabaseError(SRecordChanged);
DS := Source;
end;
try
Delta.Edit;
for I := 0 to Delta.FieldCount - 1 do
begin
Field := DS.FindField(Delta.Fields[I].FieldName);
if (Field <> nil) and (not (Field.Lookup or Field.Calculated)) and
(not BlobsOnly or (Field.IsBlob and VarIsNull(Delta.Fields[I].NewValue))) then
Delta.Fields[I].Assign(Field);
So I was hoping to do this
cdsDelta := ggDataModule.ClientDataSetEntity.Delta;
for i:= 0 to cdsDelta.FieldCount - 1 do
begin
cdsDelta.Fields[i].readonly := false;
end;
but i get Delta is empty