with ADODataSet1 do begin CursorLocation := clUseClient; CursorType := ctStatic; LockType := ltBatchOptimistic; CommandType := cmdText; CommandText := 'SELECT * FROM Employee'; Open; end;
AppayUpdate太长时间不用了,有点记不清了
使用缓存提交步骤如下: 1.比如你连接的表是用QUERY即query1 2.你增加一个UpdateSQL即updatesql1 3.将query1的updateobject设置为updatesql1 4.设置query1的cachedupdate为真 5.打开query1 6.双击updatesql1,设置其key fields为表的主键值 7.选择updatesql1的generate sql,单击即可 8.这样就可以了 9.在真正保存的代码中写: procedure TForm1.ApplyButtonClick(Sender: TObject);begin with Query1 do begin Database1.StartTransaction; try ApplyUpdates; {try to write the updates to the database}; Database1.Commit; {on success, commit the changes}; except Database1.Rollback; {on failure, undo the changes}; raise; {raise the exception to prevent a call to CommitUpdates!} end; CommitUpdates; {on success, clear the cache} end;end; 就可以了
提交时要用
ADOQuery.UpdateBactch才行
取消用ADOQuery1.CancelBatch
with ADODataSet1 do begin
CursorLocation := clUseClient;
CursorType := ctStatic;
LockType := ltBatchOptimistic;
CommandType := cmdText;
CommandText := 'SELECT * FROM Employee';
Open;
end;
1.比如你连接的表是用QUERY即query1
2.你增加一个UpdateSQL即updatesql1
3.将query1的updateobject设置为updatesql1
4.设置query1的cachedupdate为真
5.打开query1
6.双击updatesql1,设置其key fields为表的主键值
7.选择updatesql1的generate sql,单击即可
8.这样就可以了
9.在真正保存的代码中写:
procedure TForm1.ApplyButtonClick(Sender: TObject);begin
with Query1 do
begin
Database1.StartTransaction;
try
ApplyUpdates; {try to write the updates to the database};
Database1.Commit; {on success, commit the changes};
except
Database1.Rollback; {on failure, undo the changes};
raise; {raise the exception to prevent a call to CommitUpdates!}
end;
CommitUpdates; {on success, clear the cache}
end;end;
就可以了