procedure TForm6.btn2Click(Sender: TObject);
var
fld_Id:TIntegerField;
fld_Value:TStringField;
fld_Time:TDateTimeField;
i,Id:Integer;
begin
//插入
cxGrid1DBTableView1.DataController.DataSource := ds1;
ds1.DataSet := kbmtbl1;
Id := 1;
with kbmtbl1 do
begin
DisableControls; //切断数据感知控件
try
Open; //打开
//定义Field
fld_Id:=TIntegerField(FieldByName('Id'));
fld_Value:=TStringField(FieldByName('Value'));
fld_Time:=TDateTimeField(FieldByName('Time'));
for i := 0 to 9 do
begin
Inc(Id);
Append; //附加数据
//赋值
fld_Id.AsInteger := Id;
fld_Value.AsString := 'Hello YXM !'+inttostr(Id);
fld_Time.AsDateTime := Now;
FieldByName('num').Value := 100;
Post; //确定
end;
UpdateIndexes;//更新索引
finally
EnableControls; //连接数据感知控件
end;
end;
end;