在重新启动应用程序或数据库连接之前,不会更新DBGrid数据 [英] DBGrid data not updated until restarting app or DB connection

查看:112
本文介绍了在重新启动应用程序或数据库连接之前,不会更新DBGrid数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Delphi 10.2.3和Firebird 2.5.8.我有一个带有2个字段(标识和文本)的小表,可以在子窗体中进行编辑,并使用主窗体上的数据.在子表单上,我使用DBGrid& DBNavigator.每次使用时,我都会创建表格并将其销毁.

I am using Delphi 10.2.3 and Firebird 2.5.8. I have small table with 2 fields (id & text) which I edit within of a subform and use the data on my mainform. On the subform I use DBGrid & DBNavigator. On each use, I create the form and destroy it afterwards.

在我的子窗体上,每次都可以看到更新的数据.关闭子窗体后,我在主窗体中刷新列表,但是

On my subform I can see each time the updated data. After closing the subform I refresh my list within of my mainform but

SELECT Id,Text FROM Tbl_Test 

仅显示旧数据.

仅在重新启动程序后,我才能获取更新的数据.知道我做错了什么吗?顺便提一句. isql.exe也不会更新数据.我必须重新启动isql.我也测试了Firebird 2.5.6-行为没有差异.

I get the updated data only after restarting my program. Any idea what I could have done wrong? Btw. isql.exe also doesn't update the data. I have to restart isql. I tested Firebird 2.5.6 too - no difference in the behaviour.

我正在将IBDataBaseIBTable用于DBGrid和IBquery.

I am using IBDataBase and IBTablefor the DBGrid and IBquery.

当我断开IBDatabase并重新连接时,我得到了更新的数据.有没有更好的方法?

When I disconnect the IBDatabaseand reconnect then I get the updated data. Isn't there a better way?

推荐答案

很可能您有两个事务,一个事务填充网格,另一个事务更改子窗体.

Most probably you have two transactions, one to populate the grid and another to make changes in the subform.

然后,网格的事务可能是

Then, the grid's transaction is probably

  • 设置为SNAPSHOT类型,而不是READ COMMITTED类型
  • 在子表单的tx提交"更改数据后没有重新启动

通过这种方式,该事务拒绝在启动后看到引入的更改.但是,当您重新连接到数据库时,您将隐式回滚该tx并启动另一个新的网格的tx.

That way this transaction refuses to see changes introduced after it was started. But when you re-connect to the database you implicitly roll-back that tx and start another newer grid's tx.

如果是这样,您将不得不将网格的tx更改为RC类型(证明它不会破坏表单中的任何其他内容),或者手动重新启动该事务以使其查看较新的数据.

If so, you would have to either change the grid's tx to RC kind (proving it would not break anything else in the form) or manually restart that transaction to let it see the newer data.

这篇关于在重新启动应用程序或数据库连接之前,不会更新DBGrid数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆