1,手动添加字段值
cds1.Close;
cds1.CreateDataSet;
cds1..FieldByName('字段1').AsString:='测试';//字段赋值
s:=cds1..FieldByName('字段1').AsString;//字段的获取
2、代码添加字段
procedure TForm1.FormCreate(Sender: TObject); var i: Integer; begin with ClientDataSet1 do begin FieldDefs.Add('ID', ftInteger, 0, False); FieldDefs.Add('Name', ftString, 10, False); FieldDefs.Add('Gender', ftInteger, 0, False); FieldDefs.Add('Age', ftInteger, 0, False); IndexDefs.Add('PK', 'ID', [ixPrimary, ixUnique]); CreateDataSet; DisableControls; for i := 1 to 1000 do begin Append; FieldByName('ID').AsInteger := i; FieldByName('Name').AsString := 'User' + IntToStr(i); FieldByName('Gender').AsInteger := Random(2); FieldByName('Age').AsInteger := Random(100); Post; end; EnableControls; end; end; end.