How to insert a record in one table (with auto-increment) to create a record in another table with IDparent, equal to the ID (auto-increment) of the first table? I use ADOQuery and Access 2007.

  • one
    Add a trigger to the database, which will deal with it itself - Isaev
  • I did not work with triggers, I can’t even imagine the logic of working with them. How to do without them? I tried to find out when inserting the ID of the record, the cat. just inserted, does not work. - Garik Pokrovskij
  • Without a trigger is very ugly, but ... 1. Start a transaction (ADOconnection). 2. Add to the first table (only using SQL tools, for example, using ADOCommand). 3. Identify MAX (ID). 4. Add to the second (only using SQL tools, for example, using ADOCommand). 5. End of transaction. Items 3 and 4 can be performed with a single INSERT command. - Oleg53
  • DM.Query_zakaz.SQL.Clear; DM.Query_zakaz.SQL.Add ('INSERT'); // Here you can see the full code that works DM.Query_zakaz.ExecSQL; DM.Query_zakaz.close; // From here I start to get the ID of the inserted record DM.Query_zakaz.SQL.Clear; DM.Query_zakaz.SQL.Text: = 'select max (ID) as max_ID from Orders'; DM.Query_zakaz.Open; ShowMessage (DM.Query_zakaz.Fields [0] .AsString); Here I try to receive this ID. Writes: Query_zakaz: Field 'ID' not found. He can not find this field. And it exists! Autoincrement it. - Garik Pokrovskij
  • In the Заказы table, is there a field called ID ? Maybe it is called differently? - kot-da-vinci

0