象这样,执行到query1.open就完蛋了...
database1.StartTransaction;
try
query1.close;
query2.close;
query2.sql.Clear;
query2.sql.Add('select * from kc');
query2.Open;
while not query2.Eof do
begin
query1.sql.Clear;
query1.sql.Add('select settle_quantity,settle_money from g_month_account ');
query1.sql.Add('where ga_month=:ga_month and g_code=:g_code');
query1.ParamByName('ga_month').asstring:=lastmonth;
query1.ParamByName('g_code').asstring:=query2['g_code'];
query1.open;
database1.StartTransaction;
try
query1.close;
query2.close;
query2.sql.Clear;
query2.sql.Add('select * from kc');
query2.Open;
while not query2.Eof do
begin
query1.sql.Clear;
query1.sql.Add('select settle_quantity,settle_money from g_month_account ');
query1.sql.Add('where ga_month=:ga_month and g_code=:g_code');
query1.ParamByName('ga_month').asstring:=lastmonth;
query1.ParamByName('g_code').asstring:=query2['g_code'];
query1.open;
无法分析你的意图。
不过你似乎忘记在循环内部重新关闭QUERY1了。
重复打开当然出错。
query1.sql.Clear;
query1.sql.Add('select settle_quantity,settle_money from g_month_account ');
query1.sql.Add('where ga_month=:ga_month and g_code=:g_code');
我只觉得你的代码很冗余,上面的代码为什么不在Query1的 SQL属性里写好,然后再close-->parambyname(' para1').assring =:para1 ---> open 每次都CLear 再编译,多没效率!
try
你做的操作;
database1.Commit;
except
database1.rollback;
end;你的事物没有完成!