Recent

Author Topic: Best way to update data from linked tables using navigator and DBGrid?  (Read 539 times)

Lazikas o Pontios

  • New member
  • *
  • Posts: 7
HI to all!

I use the following sql query in order to show some data from main table (agros), that is linked with 3 more tables (but for the moment i pull data from 2 of them), into a DBGrid:

agros_sql_Query = 'Select owners.Name, koino.Name as Koinotita , agros.* from agros, owners, koino where owners.id = agros.owner_id and koino.id = agros.koino_id';

The connections are :
Dbgrid.Datasource:=Datasource1;
DataSource1.Dataset:=Query1;
Query1.SQL.Text:=   agros_sql_Query ; //the query is define above

The result is as expected, as you can see from the attached photo(first two fields are pulled from other tables). But the navigator is now almost disabled ( i guess it is normal behavior) since the dbgrid is not connected to a single table but into a 'virtual' one. So far, so good.
Now i want to be able to update/correct  the data from the main table (agros). Hense, the fields from Code up to Year. But since the navigator is almost disabled, i cannot.

And the main question is : Is there a workaround to update records (using or not the dbgrid)?  I want to avoid creating forms for each table because the table agros is a middle table that will be linked to other tables in one to many relation and the other tables have dozens of fields.

If it's TLTR, the question can be summurised to : Can i update a row of one table while i MUST see data from other tables that are related to that row (preferably in a DBGrid)  ?
« Last Edit: February 17, 2023, 11:14:34 am by Lazikas o Pontios »

paweld

  • Hero Member
  • *****
  • Posts: 627
Re: Best way to update data from linked tables using navigator and DBGrid?
« Reply #1 on: January 28, 2023, 04:00:13 pm »
in the UpdateSQL property, you can set an individual query that updates the data - sample in attachment
Best regards / Pozdrawiam
paweld

Lazikas o Pontios

  • New member
  • *
  • Posts: 7
Re: Best way to update data from linked tables using navigator and DBGrid?
« Reply #2 on: February 02, 2023, 12:58:49 am »
TYVM, you are a life saver !!! It worked like charm, even with MYSQL database  :D :D :D O:-).

 

TinyPortal © 2005-2018