Recent

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

kholyphoenix1

  • New member
  • *
  • Posts: 5
[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

  • Full Member
  • ***
  • Posts: 224
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 1.8.4 FPC 3.0.4 Linux Mint Mate 17.2 x86_64 GTK-2
Zeos 7.1.3 - Sqlite 3.8.2

Foro Lazarus en español http://forum.lazarus.freepascal.org/index.php/board,73.0.html

valdir.marcos

  • Hero Member
  • *****
  • Posts: 822
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: 822
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

  • Full Member
  • ***
  • Posts: 237
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 IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircrafts

kholyphoenix1

  • New member
  • *
  • Posts: 5
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