procedure TForm1.Button1Click(Sender: TObject);
begin
adoconnection1.BeginTrans;
try
begin
with adoquery1 do
 begin
 close;
 sql.Clear;
 sql.Add('insert into table2 values(:a,:b,:c)');
 parameters.ParamByName('a').Value:=edit1.Text;
 parameters.ParamByName('b').Value:=edit2.Text;
 parameters.ParamByName('c').Value:=edit3.Text;
   execsql;
 end;
 adoconnection1.CommitTrans;
 application.MessageBox('成功','tishi',64);
 end ;
except
adoconnection1.RollbackTrans;
application.MessageBox('失败','提示',64);
end;
end;
不知道为啥出错
如果我把
adoconnection1.BeginTrans;
adoconnection1.committrans;
两句删除掉
程序就能用了,

解决方案 »

  1.   

    adoconnection1.Open;
    adoconnection1.BeginTrans;
      

  2.   


    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with adoquery1  do  begin
      close;
     if not Connection.Connected then  Connection.Connected:=true;
      connection.BeginTrans;
      sql.text:='insert into table2 values(:a,:b,:c)';
      parameters.ParamByName('a').Value:=edit1.Text;
      parameters.ParamByName('b').Value:=edit2.Text;
      parameters.ParamByName('c').Value:=edit3.Text;
     try
     execsql;
     Connection.CommitTrans;
     application.MessageBox('成功','tishi',64);
     except
      Connection.RollbackTrans;
      application.MessageBox('失败','提示',64);
     end;
     end;
    end;