Hello, dear forum users, I am interested in the following: on the form are two DBGrid components, two tables connected via Master Source, the first table has a “quantity” column, it must assign a number equal to the number of rows in the second table to its cells. That is, if in the second table there are 4 lines, then the number “4” should be set in the cell. Is it possible to realize this?
I would advise not to use the T Table, but the T Query or T * DataSet. We also link everything in the Master Source, after which we write in the St. SQL of the parent table:
select p.*,(select count(c.id) from child c where c.id_par=p.id) from parented p
select * from child where id_par=:id
And who's in the way? Put the T * Query component on the form (asterisk, since I do not know which type you use). Link this component to the same base. A label - to this component. Now it's up to you to write the correct sql query.
select count(*) from имя_таблицы
It remains to make T * Query active and that's it.
If the tables are related, you can do another thing: refer to the property of the subordinate table (your Table) RecordCount - it indicates the number of records in the table, and if the tables are connected, then the number of related rows with the main table row. Then write it in a table - in the desired field, as an integer. But it is not clear to me why this is necessary - the number of records in the table can be output to some Label.