Cannot Modify Field in Client Side

From: S-Lotfi (lotfi_at_kawacomputer.com)
Date: 12/21/04


Date: Tue, 21 Dec 2004 14:51:45 +0330

Hi
Can You help me?

I have some error in the following code.This is a test code.
In this code I want to edit clientdata that provided from query execute .
This ClientDataSet dont have Source DataSet.After edit a Field in this
clientdataset this error appear "Field 'Name' Cannot be modified"!!
After this error ,Add this line before edit field
"ClientDataSet1.FieldByName('Name').ReadOnly := False" .In times after
execute ,after post clientdataset this error happen
"Trying to modify read-only field".
With this errors, what can I do for modify this Field .

thanks
S-Lotfi

-----------------
//testCode
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, DBClient, ExtCtrls, DBCtrls, Grids, DBGrids,
  StdCtrls, Buttons, Provider;

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    ADODataSet1: TADODataSet;
    DataSetProvider1: TDataSetProvider;
    BitBtn1: TBitBtn;
    ClientDataSet1: TClientDataSet;
    BitBtn2: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  ClientDataSet1.ProviderName := DataSetProvider1.Name;
  ClientDataSet1.CommandText :=
  ' select Student.Name,Class.Code From Student'+
  ' inner join Class on Class.ID=Student.ClassID';
  ClientDataSet1.Open;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
  ClientDataSet1.Edit;
  //ClientDataSet1.FieldByName('Name').ReadOnly := False;
  //ClientDataSet1.FieldByName('Name').ProviderFlags := [pfInUpdate];
  ClientDataSet1.FieldByName('Name').AsString :=
    ClientDataSet1.FieldByName('Name').AsString+'1';
  ClientDataSet1.Post;
end;

end.


Quantcast