Recent

Author Topic: [Solved] - Parameter 'user' not found.  (Read 1782 times)

kholyphoenix1

  • New Member
  • *
  • Posts: 25
[Solved] - Parameter 'user' not found.
« on: September 09, 2019, 10:53:40 pm »
Hello, i need help with this SQL.
An error is occurring that says: Parameter "user" not found.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.btnExecutar2Click(Sender: TObject);
  2. begin
  3.   SQLQuery2.Close;
  4.   SQLQuery2.SQL.Clear;
  5.   SQLQuery2.UpdateSQL.Add('UPDATE access_register SET password= :password WHERE user = :user');
  6.   SQLQuery2.Params.ParamByName('user').AsString := 'jr';
  7.   SQLQuery2.Params.ParamByName('password').AsString:= '12345';
  8.   try
  9.     //SQLQuery2.Active:=True;
  10.     //SQLQuery2.Open;
  11.     //SQLQuery2.Prepare;
  12.     SQLQuery2.ExecSQL;
  13.     SQLTransaction2.Commit;
  14.   except
  15.     on E: Exception do
  16.       begin
  17.         ShowMessage('Error: ' + E.Message );
  18.       end;
  19.   end;
  20. end;  
« Last Edit: September 10, 2019, 12:29:11 pm by kholyphoenix1 »

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: Question - Parameter 'user' not found.
« Reply #1 on: September 10, 2019, 12:02:53 am »
You must set the params before UpdateSQL.Add



Ignore me, sorry, I had a bad day...
« Last Edit: September 10, 2019, 05:30:08 am by GAN »
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Question - Parameter 'user' not found.
« Reply #2 on: September 10, 2019, 04:58:13 am »
Hello, i need help with this SQL.
An error is occurring that says: Parameter "user" not found.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.btnExecutar2Click(Sender: TObject);
  2. begin
  3.   SQLQuery2.Close;
  4.   SQLQuery2.SQL.Clear;
  5.   SQLQuery2.UpdateSQL.Add('UPDATE access _register SET password= :password WHERE user = :user');
  6.   SQLQuery2.Params.ParamByName('user').AsString := 'jr';
  7.   SQLQuery2.Params.ParamByName('password').AsString:= '12345';
  8.   try
  9.     //SQLQuery2.Active:=True;
  10.     //SQLQuery2.Open;
  11.     //SQLQuery2.Prepare;
  12.     SQLQuery2.ExecSQL;
  13.     SQLTransaction2.Commit;
  14.   except
  15.     on E: Exception do
  16.       begin
  17.         ShowMessage('Error: ' + E.Message );
  18.       end;
  19.   end;
  20. end;
Shouldn't "access _register" be only one word instead of two?

Try this one:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.btnExecutar2Click(Sender: TObject);
  2. begin
  3.   SQLQuery2.Close;
  4.   SQLQuery2.SQL.Clear;
  5.   SQLQuery2.SQL.Add('UPDATE access_register SET password= :password WHERE user = :user');
  6.   SQLQuery2.Params.ParamByName('user').AsString := 'jr';
  7.   SQLQuery2.Params.ParamByName('password').AsString:= '12345';
  8.   try
  9.     SQLQuery2.ExecSQL;
  10.     SQLTransaction2.Commit;
  11.   except
  12.     on E: Exception do
  13.       begin
  14.         ShowMessage('Error: ' + E.Message );
  15.       end;
  16.   end;
  17. end;

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Question - Parameter 'user' not found.
« Reply #3 on: September 10, 2019, 05:01:54 am »
You must set the params before UpdateSQL.Add
This doesn't seem to be relevant.

Quote
Code: Pascal  [Select][+][-]
  1. begin
  2.   SQLQuery2.Close;
  3.   SQLQuery2.SQL.Clear;
  4.   SQLQuery2.Params.ParamByName('user').AsString := 'jr';
  5.   SQLQuery2.Params.ParamByName('password').AsString:= '12345';  
  6.   SQLQuery2.UpdateSQL.Add('UPDATE access _register SET password= :password WHERE user = :user');
  7.   try
But, an UPDATE command without a SELECT command might become an issue.

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: Question - Parameter 'user' not found.
« Reply #4 on: September 10, 2019, 11:19:30 am »
He clears the SQL-Prop of his Query2, but then Adds to the UpdateSQL-Property......

Why not just
Query2.SQL.Clear;
Query2.SQL.Text:='UPDATE blablablablabnl....';
Query2.Params...blablabla;
Query2.ExecSQL;
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

kholyphoenix1

  • New Member
  • *
  • Posts: 25
Re: Question - Parameter 'user' not found.
« Reply #5 on: September 10, 2019, 12:27:15 pm »
He clears the SQL-Prop of his Query2, but then Adds to the UpdateSQL-Property......

Why not just
Query2.SQL.Clear;
Query2.SQL.Text:='UPDATE blablablablabnl....';
Query2.Params...blablabla;
Query2.ExecSQL;

Solved, i changed for 'sql.text'
Thanks all!!!  :D

 

TinyPortal © 2005-2018