HowTo update table records from controls connected to query?

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Minotaurus007
Posts: 14
Joined: Wed 27 Aug 2008 16:03

HowTo update table records from controls connected to query?

Post by Minotaurus007 » Sat 07 Feb 2009 17:13

I want to do a query, display the result, and change it.
I have:

Code: Select all

TMyTable T1, T2 
TMyQuery Q        // selecting some joins from T1, T2
Q->Edit();        // for editing
TMyDataSource QDS // connected to Q
TDBEdit QE        // To display Q, E->ReadOnly = false, of course
Although I can edit data displayed by TDBEdit QE, they are not altered permanently, not within the Query and not int the Table. But that's what I want! A simple

Code: Select all

Q->Post();
does not work. When going back to the result-record, the old result is there again. Nothing has changed. I guess I have to alter some properties. What am I missing?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 09 Feb 2009 09:40

Please make sure that the CachedUpdates property is set to False.
If it doesn't solve the problem, please try to compose a small sample to demonstrate the problem and send it to dmitryg*devart*com.

Minotaurus007
Posts: 14
Joined: Wed 27 Aug 2008 16:03

Post by Minotaurus007 » Sun 15 Feb 2009 12:27

No, CachedUpdates is set to false and it's not working.

Meanwhile I tried to connect a DBNavigatorBar to the query. However, while editing still works, the changes after pressing "nbPost" are not permanent. Pressing "nbRefresh" on the NavigatorBar restores the changes in the control (TDBEdit or TDBGrid etc.) back to the original state.

I will try to compose a small program to demonstrate it.

Minotaurus007
Posts: 14
Joined: Wed 27 Aug 2008 16:03

Post by Minotaurus007 » Sun 15 Feb 2009 13:38

Problem solved!

I missed the point that only the first table is updated in subsequent update-requests. When I changed

Code: Select all

SELECT * FROM T1, T2 WHERE...
to
SELECT * FROM T2, T1 WHERE...
everything worked, because in my application only T2 must be updated.

I already had failed to use the update property, because there was an exception as a result of identical fieldnames in two fields in both tables. Because of this one field had been automatically renamed to ID_1 (original ID) by the query. The update property failes to find ID_1 in the base table, of course, raising an exception. As a consequence I had not tried the update-property-approach anymore.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 17 Feb 2009 12:44

It is good to see that this problem has been solved.

Post Reply