Search code examples
delphidbgrid

Editable DBGrid?


I am a beginner in Delphi and I need help with the following problem. I have to implement an editable DBGrid on my form. The DBGrid displays results from a query joining 3 tables. I managed to make the DBGrid editable but the edits have no effect on the database. I can insert, edit or delete rows in the DBGrid but these changes do not get saved to the database. I have the following settings:

Query2.DatabaseName=Test
Query2.SQL=SELECT cd.hourstart, cd.hourfinish, o.objname, cd."work", cd.worktime  
           FROM Card c JOIN CardDetail cd ON c.N=cd.card  
           JOIN objects o ON cd.project=o.N  
           WHERE c.worker=5 AND c.data=CONVERT(DATE, GETDATE())
Query2.UpdateObject=UpdateSQL2  
Query2.CachedUpdates=True  
Query2.RequestLive=True

UpdateSQL2.DeleteSQL=delete from CardDetail  
                     where hourstart = :OLD_houerstart and  
                     hourfinish = :OLD_houerfinish and  
                     work = :OLD_work and  
                     worktime = :OLD_worktime
UpdateSQL2.InsertSQL=...  
UpdateSQL2.ModifySQL=...  

DataSource2.DataSet=Query2  
DBGrid2.DataSource=DataSource2 

I am probably missing something but I don't know what. Any help would be appreciated!


Solution

  • It is claimed that you need several UpdateSQL object, one per table http://docwiki.embarcadero.com/RADStudio/XE3/en/Using_Multiple_Update_Objects_Index

    Each of those objects should have base TDataSet bound to them for referencing vanilla data. http://docwiki.embarcadero.com/Libraries/en/Bde.DBTables.TDataSetUpdateObject.DataSet

    It is claimed, that ApplyUpdates/Commit/CommitUpdates should be called on different objects in proper order. http://docwiki.embarcadero.com/RADStudio/en/Applying_Cached_Updates_with_Dataset_Component_Methods

    PS. BDE is deprecated and badly compatble with recent Windows and recent db servers.