Coasting Dave
Coasting Dave

Reputation: 33

Delphi: After using AppendData(Data,False) twice to a ClientDataset, I can't edit its rows or move its cursor

I have a disconnected ClientDataset ( I dragged the component from the toolbar, right-clicked on it and in the context menu selected "Create Dataset...") which has no Provider. I load it with some records from the database like this:

someProvider.Dataset = someQuery;
someQuery.Open;
data:= someProvider.GetRecords(-1,recordsextracted,ResetOption+MetaDataOption);

if not cdsMyClientDataset.Active then 
begin 
  cdsMyClientDataset.Open; 
end;

cdsMyClientDataset.EmptyDataSet;
cdsMyClientDataset.AppendData(data,False);

The client dataset is bound with a datasource to a DbGrid, and I allow the user to add, delete or edit records. If he wants he can reload again to discard changes, and I call the code above for a second time.

But after that second call to the code above, the DbGrid doesn't work. The user can't scroll or edit any field. I can navigate and edit records programmatically just fine, but not with the DbGrid.

Upvotes: 0

Views: 2972

Answers (1)

APZ28
APZ28

Reputation: 1007

If you do not append additional data, do these instead

From
if not cdsMyClientDataset.Active then 
begin 
  cdsMyClientDataset.Open; 
end;

cdsMyClientDataset.EmptyDataSet;
cdsMyClientDataset.AppendData(data,False);

To
cdsMyClientDataset.Data := data;

Cheer Pham

Upvotes: -1

Related Questions