做了个form 使用DBGRID向数据库中写数据解决方法
做了个form 使用DBGRID向数据库中写数据
------解决思路----------------------
//delphi 7 我是新手 写的不对的 大家不要见笑啊
//sql2008
//数据库引擎使用的是BDE
//创建了一个form上面加了一个Dbgrid、Table、Query、Datasource
//Dbgrid 数据源 Datasource1 Table 的dataset 是 Table1
//现在就想 在dbgrid中写入数据后 自动保存到数据库中
//如果下次打开就打开原来写入的集合 可以修改、可以删除、可以插入
//保存的时候 只讲修改过的内容进行更新 没有修改的行不动。
//formshow内容如下:
table1.Databasename:=Abtec;
try
if Table1.Active then table1.close;
if Table1.Exists then
table1.DeleteTable;
except
end;
if Qrybh.Active then Qrybh.close;
Qrybh.open ;
myCreateTable(Table1,Qrybh); //根据查询结果创建表
table1.open;
table1.Edit ;
table1.BatchMove(Qrybh,batappend);
Qrybh.close;
dbgrid1.SetFocus;
//保存按钮过程如下:
procedure TFrmdwlxrdj.ButsaveClick(Sender: TObject);
begin
table1.edit ;
if (table1.state in [dsedit,dsinsert]) then table1.post;
end;
//这么写的每次保存的时候都没有讲结果保存 哪里搞的不对了啊 Table1.post已经 post了 为啥结果没提交捏
------解决思路----------------------
if (table1.state in [dsedit,dsinsert]) then Table1.ApplyUpdates;