当前位置: 代码迷 >> PB >> 老生常谈有关问题,大家遇到过Rows Between Retrieve and Update 吧?请问一个好的解决方案
  详细解决方案

老生常谈有关问题,大家遇到过Rows Between Retrieve and Update 吧?请问一个好的解决方案

热度:196   发布时间:2016-04-29 08:42:33.0
老生常谈问题,大家遇到过Rows Between Retrieve and Update 吧?请教一个好的解决方案
老生常谈问题,大家遇到过Rows Between Retrieve and Update 吧?请教一个好的解决方案。
不要告诉我更改 Update 和 Insert then Update等等。两种方法都会出现这个问题。

------解决方案--------------------
PB开发境界,你是哪种?



//菜鸟代码
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


------解决方案--------------------
实际开发中累积的一个情况,其他情况都很容易判断

HTML code
PB11 的 SNC SQL Native Client(OLE DB) 接口有严重的Bug 数据表的DELETE触发器涉及到自身表时(或其它)出现 Row changed between retrieve and update. 需改存储过程数据表的DELETE触发器涉及到自身表时(或其它)出现 Row changed between retrieve and update. No changes made to databASE. DELETE FROM employee WHERE emp_id = 111 AND dept_id = 21  但同样的触发器,用 MSS Microsoft SQL Server 6.X 就没问题。SQL后台person表写有触发器,在原先pb9.0时可用dw_1.update()进行更新表. 升级成pb11.5后不能更新,提示     Row changed between retrieve and update.     No changes made to database. 如果触发器只有删除一个表的数据.是正常的. 附:触发器如下: CREATE TRIGGER [delete_empwork] ON dbo.person FOR DELETE AS --删除works表中数据   delete checkrecord  from checkrecord ,deleted     where checkrecord .id_person = deleted.id_person --删除finger_mask  表中数据   delete finger_mask  from finger_mask,deleted     where finger_mask .id_person = deleted.id_person --删除w_work 表中数据   delete w_work from w_work,deleted     where w_work .id_person = deleted.id_person解决办法CREATE TRIGGER [delete_empwork] ON dbo.person FOR DELETE AS --删除works表中数据   if exists(select 1 from deleted d join checkrecord a on d.id_person = a.id_person)  delete checkrecord  from checkrecord ,deleted     where checkrecord .id_person = deleted.id_person --删除finger_mask  表中数据   if exists(select 1 from deleted d join figuer_mask a on d.id_person = a.id_person)  delete finger_mask  from finger_mask,deleted     where finger_mask .id_person = deleted.id_person --删除w_work 表中数据   if exists(select 1 from deleted d join w_work a on d.id_person = a.id_person)  delete w_work from w_work,deleted     where w_work .id_person = deleted.id_person 或者设置 set nocount on
------解决方案--------------------
哦,还有一个在使用sql server 时,如果使用了自增列,连接数据库时,需要加上以下参数
Identity='SCOPE_IDENTITY()'
如果没有这句那么,在表上有触发器时,自增的值就会出错,导致了rt的问题
------解决方案--------------------
探讨
PB开发境界,你是哪种?
……

------解决方案--------------------
我是歪门邪道级,一般窗口上定义有返回值的事件在需要保存时调用,以便关闭窗口时如数据未保存提示是否保存,要保存时如果返回值显示保存失败就不关掉窗口了,尽量少写messagebox:
long ll_update
string ls_err
  相关解决方案