怎么样取消数据录入时一换行就自动保存到数据库呢?
我用的是ADOConnection、ADOQuery,datasource组件,前端录入界面是cxGrid

解决方案 »

  1.   

    这个问题不止一个人问过,网上搜一下一大把。现给你复制一种方案:去掉DbGrid的自动添加功能 procedure TForm1.DataSource1Change(Sender: TObject; Field: 
    TField);
    begin
      if TDataSource(Sender).DataSet.Eof then 
         TDataSource(Sender).DataSet.Cancel;
    end;
      

  2.   

    在数据感知元件里面,确实会有许多你不好控制的地方,对于数据换行后自动保存的问题,我通常是这样处理的,用ClientDataSet, 以为换行后ClientDataSet可以只保存在你的内存,而不是马上就更新实际的数据库的数据,各种元件的关系如下:cxGrid(TableView) -->DataSource -->ClientDataSet --->DataSetProvider -->ADOQuery -->ADOConnection.前台取完数据后就关闭ADOQuery。这样处理就保证了数据更新又你来控制。至于为什么数据集一换行就保存了,没有去仔细研究过。也许还有更简便更好的方法。不管如何我还是建议少用和不用数据感知元件直接来挂钩数据库,因为里面很多东西不能随意控制,特别是事务处理方面。(虽然感知元件用起来很方便快捷)
      

  3.   

    至于为什么数据集一换行就保存了
    --------------------------------
    应从数据集的state上考虑:换行,即从dsEdit变为dsBrowse状态
      

  4.   

    ADOQuery使用批次更新模式。支持将所做的多条修改一次提交。
    Specifies the lock type to use when opening a dataset.Delphi syntax:property LockType: TADOLockType;C++ syntax:__property TADOLockType LockType = {read=GetLockType, write=SetLockType, default=3};DescriptionUse LockType to specify the lock type to use when opening a dataset. LockType determines whether the row locking scheme for a recordset will be pessimistic, optimistic, or read-only. To be effective, LockType must be set prior to activating the ADO dataset component.The default value of LockType is ltOptimistic.Use the LockType ltBatchOptimistic to open a dataset in batch update mode.ltBatchOptimistic Optimistic batch updates; used for batch update mode rather than immediate update mode.
      

  5.   

    说点题外话:
    刚注意到是lihuasoft(类==大米),原来偶一直以为是lihuasoft(粪==大米)
    如果不想换行保存,可以考虑用STRINGGRID!