T
talo520520
Unregistered / Unconfirmed
GUEST, unregistred user!
下面这段代码该怎么写?
里面有2个ADOQuery控件,只要有一个提交失败,就回滚
Try
ADOConn.BeginTrans;
for r:=1 to isum do
begin
instr01:=Trim(stringIn.Cells[0,r]);
instr11:=Trim(stringIn.Cells[1,r]);
with ADOQ do
begin
Active:=false;
SQL.Clear;
SQl.Add('insert into wljcdj(s_type,s_index,s_form,s_FormNo,s_no,i_sum,d_date,s_jbr,s_ds,s_check,s_gys,s_remark)');
SQL.Add(' valuesatype,:aindex,:aform,:aFormNo,:ano,:asum,:adate,:ajbr,:ads,:acheck,:agys,:aremark)');
with Parameters do
begin
ParamByName('atype').Value:=Trim(inComtype.Text);
ParamByName('aindex').Value:=instr01;
ParamByName('aform').Value:=Trim(inEditForm.Text);
ParamByName('aFormNo').Value:=Trim(FormNo.Text);
ParamByName('ano').Value:=Trim(InEditNo.Text);
ParamByName('asum').Value:=instr11;
ParamByName('adate').Value:=FormatDateTime('yyyy-MM-dd',InDTP.Date);
ParamByName('ajbr').Value:=Trim(InEditjbr.Text);
ParamByName('ads').Value:=Trim(InEditds.Text);
ParamByName('acheck').Value:=Trim(InEditcheck.Text);
ParamByName('agys').Value:=Trim(inComgys.Text);
ParamByName('aremark').Value:=Trim(InEditremark.Text);
end; // Parameters
//Prepared; //这个是做什么用的?
ExecSQL;
end; //ADOin
with ADOcao do
begin
Active:=false;
SQL.Clear;
SQL.Text:='Update YJTable set i_byrk=i_byrk+:ibyrk where s_index=:sindex';
Parameters.ParamByName('ibyrk').Value:=instr11;
Parameters[1].Value:=instr01;
ExecSQL;
end; //ADOcao
end; //for
ADOConn.CommitTrans;
except
ADOConn.RollbackTrans;
ADOin.Active:=false;
ADOcao.Active:=false;
showmessage('添加记录失败!');
exit;
end; //try
ADOin.Active:=false;
ADOcao.Active:=false;
ADOin.Requery();
ADOYJ.Requery();
ADOin.Last;
里面有2个ADOQuery控件,只要有一个提交失败,就回滚
Try
ADOConn.BeginTrans;
for r:=1 to isum do
begin
instr01:=Trim(stringIn.Cells[0,r]);
instr11:=Trim(stringIn.Cells[1,r]);
with ADOQ do
begin
Active:=false;
SQL.Clear;
SQl.Add('insert into wljcdj(s_type,s_index,s_form,s_FormNo,s_no,i_sum,d_date,s_jbr,s_ds,s_check,s_gys,s_remark)');
SQL.Add(' valuesatype,:aindex,:aform,:aFormNo,:ano,:asum,:adate,:ajbr,:ads,:acheck,:agys,:aremark)');
with Parameters do
begin
ParamByName('atype').Value:=Trim(inComtype.Text);
ParamByName('aindex').Value:=instr01;
ParamByName('aform').Value:=Trim(inEditForm.Text);
ParamByName('aFormNo').Value:=Trim(FormNo.Text);
ParamByName('ano').Value:=Trim(InEditNo.Text);
ParamByName('asum').Value:=instr11;
ParamByName('adate').Value:=FormatDateTime('yyyy-MM-dd',InDTP.Date);
ParamByName('ajbr').Value:=Trim(InEditjbr.Text);
ParamByName('ads').Value:=Trim(InEditds.Text);
ParamByName('acheck').Value:=Trim(InEditcheck.Text);
ParamByName('agys').Value:=Trim(inComgys.Text);
ParamByName('aremark').Value:=Trim(InEditremark.Text);
end; // Parameters
//Prepared; //这个是做什么用的?
ExecSQL;
end; //ADOin
with ADOcao do
begin
Active:=false;
SQL.Clear;
SQL.Text:='Update YJTable set i_byrk=i_byrk+:ibyrk where s_index=:sindex';
Parameters.ParamByName('ibyrk').Value:=instr11;
Parameters[1].Value:=instr01;
ExecSQL;
end; //ADOcao
end; //for
ADOConn.CommitTrans;
except
ADOConn.RollbackTrans;
ADOin.Active:=false;
ADOcao.Active:=false;
showmessage('添加记录失败!');
exit;
end; //try
ADOin.Active:=false;
ADOcao.Active:=false;
ADOin.Requery();
ADOYJ.Requery();
ADOin.Last;