S
S
sorry_i_noob2019-06-07 02:03:51
Delphi
sorry_i_noob, 2019-06-07 02:03:51

Why if you add a value to the database through a variable, then "ADOQuery1" is added, and if directly, then a normal value?

Hello.
There is such a code

procedure TForm1.FramePositionsAdd1ButtonAddClick(Sender: TObject);
var
  Name: String;
begin
    Name := FramePositionsAdd1.EditName.Text;

    with FramePositionsAdd1.ADOQuery1 do
    begin;
    SQL.Clear;
    SQL.Text := 'INSERT INTO Должности ' +
    '(Наименование) ' +
    'VALUES ' +
    '(:title)';
    Parameters.ParamByName('title').Value := Name;
    ExecSQL;
    end;
end;

The value is added to the database, but FramePositionsAdd1.EditName.Textthe string "ADOQuery1" is added instead.
I tried to remove the variable Name. One line changes:
Parameters.ParamByName('title').Value := FramePositionsAdd1.EditName.Text;

And everything starts to add correctly. What is the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Exteris, 2019-06-07
@Exteris

WITH is evil.
You add the value FramePositionsAdd1.ADOQuery1.Name to the database

K
Konstantin Tsvetkov, 2019-06-07
@tsklab

procedure TForm1.FramePositionsAdd1ButtonAddClick(Sender: TObject);
begin
  FramePositionsAdd1.ADOQuery1.SQL.Text := 'INSERT INTO Должности (Наименование) ' +
      'VALUES ''' + FramePositionsAdd1.EditName.Text + ''''
  FramePositionsAdd1.ADOQuery1.ExecSQL;
end;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question