主  题:看看这一行代码,实在太采了,急急急急
作  者:ysmstoneman
所属论坛:软件工程
问题点数:50
回复次数:0
人气指数:0
发表时间:2001-12-18 10:00:06
 
with CEMDB.TbEmpInfo do  //TbEmpInfo:TTable
  begin
  Database.StartTransaction;
    try
      Edit;
      post;
//    ApplyUpdates; //try to write the updates to the database;
      Database.Commit; //on success, commit the changes;
    except
      Database.Rollback; //on failure, undo the changes;
    raise; //raise the exception to prevent a call to CommitUpdates!
    end;
  CommitUpdates; //on success, clear the cache
  end;
高手能不能说一下table控件的用法,为什么我用post方法不能写进数据库,用applyUpdate也不行呢?
********************************************
我用一个DataModule来管理数据集控件,用一个Database和Session来连接数据库,在用table连接database,然后在form中的DBGrid修改数据,但却不能  
******************************************
要是用query控件,又怎样呢?暂时准备50分。
 

解决方案 »

  1.   

    with CEMDB.TbEmpInfo do  //TbEmpInfo:TTable
      begin
      Database.StartTransaction;
        try
          Edit;
          post;
          ApplyUpdates; 
          Database.Commit; 
          Showmessage('Commit');
        except
          Database.Rollback; 
          raise; //raise the exception to prevent a call to CommitUpdates!
          showmessage('except');
        end;
      CommitUpdates; //on success, clear the cache
      Showmessage('ok');
     end;
    -----------------------------你可以加入showmessage看程序是怎么执行的,或者试一下这个方法:
    with CEMDB.TbEmpInfo do  //TbEmpInfo:TTable
      begin
          try
          Database.StartTransaction;
          Edit;
          post;
    //    ApplyUpdates; //try to write the updates to the database;
          Database.Commit; //on success, commit the changes;
          CommitUpdates;
          showmessage('success');    
        except
          Database.Rollback; //on failure, undo the changes;
          raise; //raise the exception to prevent a call to CommitUpdates!
          showmessage('failure');
        end;
       //on success, clear the cache
      end;
      

  2.   

    不行,它提示‘No user transaction is currently in progress'
      

  3.   

    try
      edit;
      post;?? 你还没有修改,怎么就保存???
      ……
    这样肯定不行,你应该把edit放在另外的处理里面,不要跟保存放在一起,除非你真的修改了,
      

  4.   

    上面说的对,可以先刷新,再设为edit状态,开始修改,然后执行,保存
      

  5.   

    但我把edit放在另外的处理里面,不跟保存放在一起,它提示说table没有处于修改模式