问题
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
shows me only the old data.
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.
I am using IBDataBase
and IBTable
for the DBGrid and IBquery
.
When I disconnect the IBDatabase
and reconnect then I get the updated data. Isn't there a better way?
回答1:
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
- set up as SNAPSHOT kind, not READ COMMITTED kind
- is not restarted after the subform's tx "commits" changed data
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.
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.
来源:https://stackoverflow.com/questions/51288432/dbgrid-data-not-updated-until-restarting-app-or-db-connection