I
IT书生
Unregistered / Unconfirmed
GUEST, unregistred user!
Adoconnection,Adoquery,事务中有update,insert,但update无效。以下是部份代码:
(1)开始事务部份
procedure TFrmYwglKdCzgrjf.BkdClick(Sender: TObject);
begin
.....
frmdm.ADOConn.BeginTrans;
if kd then begin //kd为函数。
frmdm.ADOConn.CommitTrans;
Application.MessageBox('开单成功,请进行打印操作!', '提示信息', mb_ok or mb_iconinformation);
end else begin
frmdm.ADOConn.RollbackTrans;
Application.MessageBox('开单失败!', '提示信息', mb_ok or mb_iconinformation);
end;
end;
(2)KD函数,主要进行数据操作。
function TFrmYwglKdCzgrjf.KD: boolean;
var
wherestr1:string;
begin
Result := True;
try
wherestr1:=' where grbh='+inttostr(grbh)+' and djh=0 and sfczdj=''是'' and sfgrzhbj=''否''';
with frmdm.ADOQ1 do
begin
close;
sql.Text := 'insert into djh(ybnd,kdlxbh,kdsj,kdczy,ms,sfylr) values(' + l7.Caption + ',13,''' + l2.Caption + ''',''' + l18.Caption + ''',''' + trim(edit2.text) + ''',''否'')';
execsql;
sql.Text := 'select @@identity'; //得到序号
open;
G_djh := fields[0].AsInteger;
close;
sql.Text := 'update zjjhmx set djh=' + inttostr(G_djh)+''+ wherestr1;
execsql; //此处在事务执行完后,数据没有更新!!!!
G_CountNum(G_djh);//调用计算函数,
close;
sql.Clear;
sql.Add('insert into jffzdj(djh,ybnd,dwbh,zje,gryj,dwyj,znj,tcyj,dwhrzh,zhyj,zhkjdbtc,zhsj,sfczdj,sfbj)');
sql.Add('values('+ inttostr(G_djh) + ',' + inttostr(G_Ybnd) + ',' + inttostr(dwbh) + ',' + floattostr(G_zje+G_znj) + ',');
sql.Add(''+floattostr(G_gryj) + ',' + floattostr(G_dwyj) + ',' + floattostr(G_znj) + ',');
sql.Add(''+floattostr(G_tcyj) + ',' + floattostr(G_dwhrzh) + ',' + floattostr(G_zhyj) + ',');
sql.Add(''+floattostr(G_zhkjdbtc) + ',' + floattostr(G_zhsj) + ',''否'','''+G_sfbj+''')');
execsql; //此处在事务的执行后,数据库有记录。
end;
except
Result := False;
end;
end;
(3)计算函数:
procedure TFrmYwglKdCzgrjf.G_CountNum(djh: integer);
begin
with frmdm.ADOQtmp do
begin
close;
sql.Text := 'select sum(gryj),sum(dwyj),sum(tcyj),sum(dwhrzh),sum(zhyj), sum(zhkjdbtc),sum(zhsj) from zjjhmx where djh=' + inttostr(djh) + '';
open;
G_gryj := fields[0].AsFloat;
G_dwyj := fields[1].AsFloat;
.......
close;
sql.Text:='select dwbh from gr where bh='+inttostr(grbh)+'';
open;
dwbh:=fields[0].AsInteger;
end;
end;
以上是事务执行的全部代码,以前的贴子也都差不多查了,请有相似经验的,经验丰富的
高人出手,在此先行谢过了。 ^_^
(1)开始事务部份
procedure TFrmYwglKdCzgrjf.BkdClick(Sender: TObject);
begin
.....
frmdm.ADOConn.BeginTrans;
if kd then begin //kd为函数。
frmdm.ADOConn.CommitTrans;
Application.MessageBox('开单成功,请进行打印操作!', '提示信息', mb_ok or mb_iconinformation);
end else begin
frmdm.ADOConn.RollbackTrans;
Application.MessageBox('开单失败!', '提示信息', mb_ok or mb_iconinformation);
end;
end;
(2)KD函数,主要进行数据操作。
function TFrmYwglKdCzgrjf.KD: boolean;
var
wherestr1:string;
begin
Result := True;
try
wherestr1:=' where grbh='+inttostr(grbh)+' and djh=0 and sfczdj=''是'' and sfgrzhbj=''否''';
with frmdm.ADOQ1 do
begin
close;
sql.Text := 'insert into djh(ybnd,kdlxbh,kdsj,kdczy,ms,sfylr) values(' + l7.Caption + ',13,''' + l2.Caption + ''',''' + l18.Caption + ''',''' + trim(edit2.text) + ''',''否'')';
execsql;
sql.Text := 'select @@identity'; //得到序号
open;
G_djh := fields[0].AsInteger;
close;
sql.Text := 'update zjjhmx set djh=' + inttostr(G_djh)+''+ wherestr1;
execsql; //此处在事务执行完后,数据没有更新!!!!
G_CountNum(G_djh);//调用计算函数,
close;
sql.Clear;
sql.Add('insert into jffzdj(djh,ybnd,dwbh,zje,gryj,dwyj,znj,tcyj,dwhrzh,zhyj,zhkjdbtc,zhsj,sfczdj,sfbj)');
sql.Add('values('+ inttostr(G_djh) + ',' + inttostr(G_Ybnd) + ',' + inttostr(dwbh) + ',' + floattostr(G_zje+G_znj) + ',');
sql.Add(''+floattostr(G_gryj) + ',' + floattostr(G_dwyj) + ',' + floattostr(G_znj) + ',');
sql.Add(''+floattostr(G_tcyj) + ',' + floattostr(G_dwhrzh) + ',' + floattostr(G_zhyj) + ',');
sql.Add(''+floattostr(G_zhkjdbtc) + ',' + floattostr(G_zhsj) + ',''否'','''+G_sfbj+''')');
execsql; //此处在事务的执行后,数据库有记录。
end;
except
Result := False;
end;
end;
(3)计算函数:
procedure TFrmYwglKdCzgrjf.G_CountNum(djh: integer);
begin
with frmdm.ADOQtmp do
begin
close;
sql.Text := 'select sum(gryj),sum(dwyj),sum(tcyj),sum(dwhrzh),sum(zhyj), sum(zhkjdbtc),sum(zhsj) from zjjhmx where djh=' + inttostr(djh) + '';
open;
G_gryj := fields[0].AsFloat;
G_dwyj := fields[1].AsFloat;
.......
close;
sql.Text:='select dwbh from gr where bh='+inttostr(grbh)+'';
open;
dwbh:=fields[0].AsInteger;
end;
end;
以上是事务执行的全部代码,以前的贴子也都差不多查了,请有相似经验的,经验丰富的
高人出手,在此先行谢过了。 ^_^