S
S
sorry_i_noob2019-06-08 23:40:39
Delphi
sorry_i_noob, 2019-06-08 23:40:39

Why does the SQL.active property need to be set to true to select a row in the database via TADOQuery, but not to insert it?

Hello. There is such a code.

procedure TFormMain.Button7Click(Sender: TObject);
begin;

  FormMain.QueryOrganizer.SQL.Clear;
  FormMain.QueryOrganizer.SQL.Text := 'INSERT INTO Органайзер ' +
  '([Код поручения], [Код работника]) ' +
  'VALUES ' +
  '(1, 1)';
  FormMain.QueryOrganizer.ExecSQL;
 
  FormMain.QueryOrganizer.SQL.Clear;
  FormMain.QueryOrganizer.SQL.Text := 'SELECT * FROM Органайзер;';
  FormMain.QueryOrganizer.Active := true;
  FormMain.QueryOrganizer.ExecSQL;
  ShowMessage(FormMain.QueryOrganizer.FieldByName('Код').AsString);

  FrameOrganizer1.DBGrid1.Datasource.Dataset.Close;
  FrameOrganizer1.DBGrid1.Datasource.Dataset.Open;

end;

If you comment out the line
FormMain.QueryOrganizer.Active := true;
Then SELECT will not work - a popup will be issued with the message "QueryOrganizer: Field 'Code' not found". However, INSERT will still work. Why is that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-06-09
@sorry_i_noob

Because it INSERTdoes not return the "Code" field.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question