TQuery的CachedUpdates必須陪合TUpdateSQL控制項才能使用

來源:互聯網
上載者:User

ExeSQL是直接執行SQL語句,而與CachedUpdates沒有任何關係。

CachedUpdates是指對TTable或TQuery中的已修改的資料進行緩衝,直到調用
ApplyUpdates.

ApplyUpdates是對TQuery或TTable中已修改,但為提交的資料進行提交,
並且只有在TQuery或TTable對象的CachedUpdates=True且Active=True,
State=dsbrowse時才能調用。

TQuery的CachedUpdates必須陪合TUpdateSQL控制項才能使用。
例如:
    Query1.SQL.Text:='select field1,field2 from table1';
    Query1.CachedUpdates:=True;
    Query1.UpdateObject:=UpdateSQL1;
    UpdateSQL1.InsertSQL:='insert table1(field1,field2) values (:field1,:field2)';
    UpdateSQL1.deleteSQL:='delete from table1 where field1=:field1,field2=:field2';
    UpdateSQL1.ModifySQL:='update table1 set field1=:field1,field2=:field2 where field1=:old_field1 and field2=:old_field2;

    Query1.Open;
    Query1.First;
    while not Query1.Eof  do begin
       Query1.Edit;
       Query1.FieldByName('field1').AsString:='123';
       Query1.Post; //此時資料並未提交到後台。
       Query1.Next;
    end;
    Query1.Database.StartTransaction
    try
      Query1.ApplyUpdates;
      Query1.Database.Commit;
   except
      Query1.Database.Rollbback;
      raise;
   end;  
   Query1.CommitUpdates;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.