//菜鸟代码
dw_1.Update()
dw_2.Update()
初级代码
IF dw_1.Update() = 1 And dw_2.Update() = 1 THEN
COMMIT;
ELSE
ROLLBACK;
END IF
中级代码
IF dw_1.Update() = 1 THEN
IF dw_2.Update() = 1 THEN
COMMIT;
ELSE
MessageBox("提示","喝多了!")
ROLLBACK;
END IF
ELSE
MessageBox("提示","喝多了!")
ROLLBACK;
END IF
高级代码
IF dw_1.Update() = 1 THEN
IF dw_2.Update() = 1 THEN
COMMIT;
ELSE
ROLLBACK;
MessageBox("提示","少喝点!")
END IF
ELSE
ROLLBACK;
MessageBox("提示","少喝点!")
END IF
专家级代码
IF dw_1.Update(True,False) = 1 THEN
IF dw_2.Update(True,False) = 1 THEN
dw_1.ResetUpdate()
dw_2.ResetUpdate()
COMMIT;
ELSE
ROLLBACK;
MessageBox("提示","没喝高啊!")
END IF
ELSE
ROLLBACK;
MessageBox("提示","没喝高啊!")
END IF
多个DW进行update,有时会不能全部成功update 用事务处理时,多个DW进行update后,再COMMIT.偶然会发现前面几个DW update成功,但后面的表失败时,好像执行了COMMIT,不会rollback.
正确的写法如下:
if dw_1.update(true, false)= 1 and dw_2.update(true, false)=1 ... then
commit;
dw_1.resetUpdate();
dw_2.resetUpdate();
...
else
rollback;
end if
说明:dw_restUpdate()作用
Clears the update flags in the primary and filter buffers and empties the delete buffer of a DataWindow or DataStore.
Usage :
When a row is changed, inserted, or deleted, its update flag is set, making it marked for update. By default the Update method turns these flags off. However, if you want to coordinate updates of more than one DataWindow or DataStore, you can prevent Update from clearing the flags. Then after you verify that all the updates succeeded, you can call ResetUpdate for each DataWindow to clear the flags. If one of the updates failed, you can keep the update flags, prompt the user to fix the problem, and try the updates again.
You can find out which rows are marked for update with the GetItemStatus method. If a row is in the delete buffer or if it is in the primary or filter buffer and has NewModified! or DataModified! status, its update flag is set. After update flags are cleared, all rows have the status NotModified! or New! and the delete buffer is empty.