Datagrid里怎么实现添加并不要自动保存,
我想输完了(多条)记录之后再统一保存!

解决方案 »

  1.   

    使用UpdateBatch; Post时候仅仅保存在内存,不保存到数据库中。
    procedure UpdateBatch(AffectRecords: TAffectRecords = arAll);
    取消使用
    procedure CancelBatch(AffectRecords: TAffectRecords = arAll);
    需要设置
    LockType := ltBatchOptimistic.
      

  2.   

    不好意思,初学DELPHI,这个方法不会用,能不能再说得详细点?
      

  3.   

    请问UpdateBatch是什么?我的数据集没有这个方法啊
      

  4.   

    你用ADO还是BDE?难道你用的跟我们的不一样?
      

  5.   

    使用UpdateBatch; Post时候仅仅保存在内存,不保存到数据库中。 
    procedure UpdateBatch(AffectRecords: TAffectRecords = arAll); 
    取消使用 
    procedure CancelBatch(AffectRecords: TAffectRecords = arAll); 
    需要设置 
    LockType := ltBatchOptimistic
      

  6.   

    我用的是ADO,没有找到这个方法啊,是不是adoquery里面的?在哪里啊
      

  7.   

    看来,你是被叶子给障目了,我就帮到底好了!
    TADOQuery, TADOTable都有这个属性
    给你代码看看:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ADODB, DB;type
      TForm1 = class(TForm)
        ADOTable1: TADOTable;
        ADOQuery1: TADOQuery;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      ADOTable1.LockType := ltBatchOptimistic;
      ADOTable1.UpdateBatch;
      ADOQuery1.LockType := ltBatchOptimistic;
      ADOQuery1.UpdateBatch; //像数据库保存的时候调用它。//本地保存调用postend;end.
      

  8.   


    我试了几次,还是不会用,调用updatebatch之前,对数据库的所有修改
    应该是存在缓存中,那怎么显示在dbgrid中呢。怎么显示不了?
      

  9.   

    首先要设置adodataset的属性:
    1.CursorType:keyset或static
    2.locktype:batchoptimistic
    3.SQL命令必须是select
    4.cursorlocation为clUseClient
      

  10.   

    接着再使用
    procedure UpdateBatch(AffectRecords: TAffectRecords = arAll); 
     
    procedure CancelBatch(AffectRecords: TAffectRecords = arAll); 
      

  11.   

    请问下面这句为什么会报错:  if ADOQryData.State in ([DB.dsInsert,DB.dsEdit]) then
         ADOQryData.UpdateBatch;---------------------------
    Debugger Exception Notification
    ---------------------------
    Project l.exe raised exception class EDatabaseError with message 'ADOQryData: Dataset not in edit or insert mode'. Process stopped. Use Step or Run to continue.
    ---------------------------
    OK   Help   
    ---------------------------