请参考: with adoquery do begin close; sql.clear; sql.Add('delete from D_CPKCTJ where D_CPKCTJ.ny=''200205'''); execsql; open; end; 用adoconnection1的execute方法: adoconnection1.execute('insert into desttable select '200205' as ny,ckbm as ckbh,xs,xjs from sourcetable where je>0');
你需要Refresh的是界面上控件关联的dataset而不是你运行delete的adoquery
with adoquery do
begin
close;
sql.clear;
sql.Add('delete from D_CPKCTJ where D_CPKCTJ.ny=''200205''');
execsql;
open;
end;
用adoconnection1的execute方法:
adoconnection1.execute('insert into desttable select '200205' as ny,ckbm as ckbh,xs,xjs from sourcetable where je>0');
ExecSQL在没有返回内容的SQL语句时使用,例如Alter, Delete, Insert, Drop等。如果没猜错,你的程序中使用的不是adoquery进行数据显示的,在你使用adoquery删除数据以后,最好将先是数据源刷新一次。例如如果你使用的是Table作为显示数据源,那么在adoquery删除数据后,可以写入以下的内容刷新显示:
Table.Close;
Table.Open;
试验1;
......
execsql;
close;
open;
//放干净绶存的数据
这样的话他会提示“不能返回一个有结果的数据集”,好像就是执行完execsql在执行open出现的那个语句。
试验2,
......
execsql;
adodataset.refresh;
会提示“缺少更新或刷新的键列信息”;
试验3,
...
execsql
adoquery.refresh;
提示,cannot perform this operation on the close...大概是这样。
最后解决方法:
execsql
adodataset.close;
adodataset.open;
adodataset.close;
adodataset.open;//这样花费的时间是很大的,如果是一个比较大的数据,你会提不尝失的;
execsql;
open;
close;
open;
..用时最少;......
execsql;
open;
adodataset.refresh;//速度在二者之中,你选吧;
adodataset.close;
adodataset.open;//这样花费的时间是很大的,如果是一个比较大的数据,你会提不尝失的;
execsql;
open;
close;
open;
..用时最少;......
execsql;
open;
adodataset.refresh;//速度在二者之中,你选吧;
execsql;
open;
adodataset.refresh;
执行不成功
试试这个
adodataset.close;
adodataset.open;
open 用于带有返回值的,
delete 用execsql就kyadoquery1.execsql;
adoquery1.refresh;
只有adodataset.close;
adodataset.open;
才能成功。可惜据说性能不好。不知道有没有什么更好的解决办法。第二个问题,已经解决。用adoconnection.execute居然可以执行sql语句,太神奇了。那岂不是,根本不需要adoquery语句,全都用adoconnection搞定。