delphi 7 用ADO连接MSSQL数据库, 界面用的是 delphi 自带的数据库绑定控件(如编辑框还有网格), 数据集是 TAdoQuery 或 TAdoCommand, 数据集的 lockType 属性是 bathUpdate, 请问如何在窗体关闭的时候自动检测数据集是否修改?包括新增和编辑记录的情况.
先谢了.

解决方案 »

  1.   

    formcloseif adoquery1.state in [dsedit,dsinsert] then adoquery1.post;
      

  2.   

    这种方法在数据集的 lockType 属性是 batchUpdate 时, 当当前记录离开已经修改的记录后, 无效, 请问还有其他的方法吗?
    谢谢!
      

  3.   

    可以声明一个标识变量,在所有可能修改数据的事件中对标识变量赋值,
    最后在需要提交数据时检查,比如AfterEdit什么的
      

  4.   

    if adotable1.modified then
           begin
                          end;
      

  5.   

    可以这样:
    1、在AfterPost事件中将DBGrid的行标识为“高亮”;
    2、在UpdateBatch之后,将DBGrid的“高亮”行恢复为正常;
    3、在用户关闭窗口时,查询DBGrid是否有“高亮”行,若有,则提示用户是否修改;
      

  6.   

    Use FilterGroup to filter the recordset displayed with an ADO dataset component. The filter requires the dataset be in update batch mode and the rows are filtered based on the update status of individual rows. Set FilterGroup to a TFilterGroup constant to filter the dataset to show just the rows that match that batch update status. For instance, set FilterGroup to fgPendingRecords to show just the rows that have been modified since the last update application.if (ADODataSet1.LockType = ltBatchOptimistic) then begin
      ADODataSet1.Filtered := True;
      ADODataSet1.FilterGroup := fgPendingRecords;
      if ADODataSet1.RecordCount>0 then ShowMessage('修改过');
    end;
      

  7.   

    if adoquery1.state in [dsedit,dsinsert] then 
      

  8.   

    下面这个函授就可判断,是否修改过
    function  IfModify(qry:TADOQuery) :boolean;
    begin
       if qry.Active then
          begin
            qry.Filtered :=true;
            qry.FilterGroup:=fgPendingRecords;
            if qry.RecordCount >0 then
               result:=true
            else
               result:=false;
            qry.Filtered :=false
          end  else
       result:=false;
    end;