阿
阿器
Unregistered / Unconfirmed
GUEST, unregistred user!
想要将tbl-in-voucher的数据转入历史表中tbl-in-voucher-history,附上代码.
现象:insert tbl-in-voucher-history语句似乎不起作用,但delete却毫不客气
的将tbl-in-voucher的数据删除了.如果不使用事务,则无此现象.困惑啊!
adoconnection1的isolationlevel的值使用的缺省值:ilCursorStability
代码如下:
procedure Tf_room.Button1Click(Sender: TObject);
var
time1:string;
time2:string;
begin
if messagedlg('确实将数据转入历史表中吗',mtconfirmation,[mbyes,mbno],0)=mryes then
begin
time1 := datetimetostr(datetimepicker1.DateTime);
time2 := datetimetostr(datetimepicker2.DateTime);
try
dm.DataModule1.ADOConnection1.BeginTrans ;
with dm.DataModule1.qry_tem do
begin
close;
sql.Clear ;
sql.Add (' insert tbl_in_voucher_history ');
sql.Add (' select * from tbl_in_voucher ');
sql.Add (' where in_date between '+''''+time1+'''');
sql.Add (' and '+''''+time2+'''');
// showmessage(sql.text);
try
execsql;
except
raise ;
end;
close;
sql.Clear ;
sql.Add (' delete tbl_in_voucher ');
sql.Add (' where in_date between '+''''+time1+'''');
sql.Add (' and '+''''+time2+'''');
// showmessage(sql.text);
try
execsql;
except
raise ;
end;
end;
//正常
dm.DataModule1.ADOConnection1.CommitTrans ;
except
//异常
dm.DataModule1.ADOConnection1.RollbackTrans ;
showmessage('发生异常,事务回退');
end;
end;
end;
现象:insert tbl-in-voucher-history语句似乎不起作用,但delete却毫不客气
的将tbl-in-voucher的数据删除了.如果不使用事务,则无此现象.困惑啊!
adoconnection1的isolationlevel的值使用的缺省值:ilCursorStability
代码如下:
procedure Tf_room.Button1Click(Sender: TObject);
var
time1:string;
time2:string;
begin
if messagedlg('确实将数据转入历史表中吗',mtconfirmation,[mbyes,mbno],0)=mryes then
begin
time1 := datetimetostr(datetimepicker1.DateTime);
time2 := datetimetostr(datetimepicker2.DateTime);
try
dm.DataModule1.ADOConnection1.BeginTrans ;
with dm.DataModule1.qry_tem do
begin
close;
sql.Clear ;
sql.Add (' insert tbl_in_voucher_history ');
sql.Add (' select * from tbl_in_voucher ');
sql.Add (' where in_date between '+''''+time1+'''');
sql.Add (' and '+''''+time2+'''');
// showmessage(sql.text);
try
execsql;
except
raise ;
end;
close;
sql.Clear ;
sql.Add (' delete tbl_in_voucher ');
sql.Add (' where in_date between '+''''+time1+'''');
sql.Add (' and '+''''+time2+'''');
// showmessage(sql.text);
try
execsql;
except
raise ;
end;
end;
//正常
dm.DataModule1.ADOConnection1.CommitTrans ;
except
//异常
dm.DataModule1.ADOConnection1.RollbackTrans ;
showmessage('发生异常,事务回退');
end;
end;
end;