procedure TForm1.Button1Click(Sender: TObject);
begin
  if not ADOConnection1.InTransaction then
    AdoConnection1.BeginTrans;
  try    ADOQuery1.Close;
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Text:= 'SELECT * FROM TPath ';
    ADOQuery1.Open;
    // do……
    ADOQuery1.Close;
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Text:= 'UPDATE TPath SET '
      + ' PathDesc =''' + Edit2.Text + ''','
      + ' KM = '+ Edit3.Text +' ';
    + ' WHERE PathID=''P006'' ';
    ADOQuery1.ExecSQL;    if ADOConnection1.InTransaction then
      ADOConnection1.CommitTrans;
  except
    if ADOConnection1.InTransaction then
      ADOConnection1.RollbackTrans;
    ShowMessage('保存操作失败,数据库连接错误!');
  end;
end;执行后出错,
ADOConnection和ADOQuery大多是默认设置
不知有人碰见过吗?
难道ADOConnection的事务处理在查询后就不能执行其他SQL语句?
如果用不同的ADOQuery就不会出错!
想不明白,请高手指点!如何使用同一ADOQuery而不出错?

解决方案 »

  1.   

    + ' KM = '+ Edit3.Text +' ';
        + ' WHERE PathID=''P006'' ';
    应该
      + ' KM = '+ Edit3.Text +' '
        + ' WHERE PathID=''P006'' ';
        
      

  2.   


    我知道是什么原因了
    因为TADODataset的CursorType设成了crUseServer
    就是使用服务器端游标了
    Thank you the same way.
      

  3.   

    请教高手!
    我的事务处理中用同一个TADOQuery执行了多次Select以及UPdate-Insert等操作;
    事务处理中TADOQuery的CursorLoacation和CursorType 要如何设置呢?
    才不会出错呢*
      

  4.   

    Cursortype:=ctkeyset
    CursorLoacation ? 好像 放哪边都可以吧 ... Study 
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      try
        if not ADOConnection1.InTransaction then
        AdoConnection1.BeginTrans;
        ADOQuery1.SQL.Clear;
        ADOQuery1.SQL.Text:= 'SELECT * FROM TPath ';
        ADOQuery1.Open;
        // do……
        ADOQuery1.SQL.Clear;
        ADOQuery1.SQL.Text:= 'UPDATE TPath SET '
          + ' PathDesc =''' + Edit2.Text + ''','
          + ' KM = '+ Edit3.Text +' ';
        + ' WHERE PathID=''P006'' ';
        ADOQuery1.ExecSQL;
        if ADOConnection1.InTransaction then
          ADOConnection1.CommitTrans;
      except
        ShowMessage('保存操作失败,数据库连接错误!');
      end;
        if ADOConnection1.InTransaction then
          ADOConnection1.RollbackTrans;
    end;
    OK!你可以试一下了。
      

  6.   

    哪位兄弟帮忙解释一下IsolationLevel事务隔离级别
    Mode
    LockType 
    CursorType
    CursorLocation
    的用法
      

  7.   

    anh(hananying) ,不是这个问题。
    thanks!
    我已经自己解决了。
    准备结帐了……还有人来领分吗?
      

  8.   

    执行select的用一个Query,执行update、delete、insert等不返回数据集的用一个Query,这两种sql语句分别用不同的Query