X
X
xxx9x2020-05-18 16:51:19
Delphi
xxx9x, 2020-05-18 16:51:19

How to link two delphi tables?

Good afternoon! I'm new, so don't judge too harshly.

The bottom line is this: I have a program with a database where there are 5 tables. In the sales table , when adding, I specify the consultant from the employees table . In the employees table itself , I have a column called "number of sales". The bottom line is that when adding any sale, I have 1 added to the "number of sales" for a certain employee.
I work through ADOTable. Hopefully the screenshots will make things clearer.

On the save button in the "Add sale" form, I decided to insert the following code:

form1.ADOTable3.first; \\ ADOTable3 - таблица с сотрудниками, ADOTable2 - таблица с продажами
sotrud:=form1.ADOTable3.FieldByName('ФИО').asstring;
while not form1.ADOTable3.eof do
begin
if dbcombobox2.text = sotrud then \\ в dbcombobox отображаются ФИО из таблицы "сотрудники"
 \\ тут не знаю, какой код написать, чтобы в таблице сотрудники, в столбце кол-во продаж, у меня прибавлялось 1
end;


Screenshots:
5ec292a942e00616051595.jpeg
5ec292b495400031550070.jpeg
5ec292ba73ab6225202918.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hemul GM, 2020-05-18
@xxx9x

form1.ADOTable3.first; \\ ADOTable3 - таблица с сотрудниками, ADOTable2 - таблица с продажами
sotrud:=form1.ADOTable3.FieldByName('ФИО').asstring;
while not form1.ADOTable3.eof do
begin
  if dbcombobox2.text = sotrud then \\ в dbcombobox отображаются ФИО из таблицы "сотрудники"
  begin
    ADOTable3.FieldByName('название поля с числом').AsInteger := ADOTable3.FieldByName('название поля с числом').AsInteger + 1;
    Brake;
  end;
end;

But this is very bad code. In your case, it is recommended to execute SQL queries, and not manipulate the data that has been loaded. With an SQL query, you would write just one line of code and without any loops.
So learn how to execute ADO sql queries in Delphi .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question