Lazarus

Programming => Databases => Topic started by: kholyphoenix1 on September 09, 2019, 10:53:40 pm

Title: [Solved] - Parameter 'user' not found.
Post by: kholyphoenix1 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;  
Title: Re: Question - Parameter 'user' not found.
Post by: GAN on September 10, 2019, 12:02:53 am
You must set the params before UpdateSQL.Add



Ignore me, sorry, I had a bad day...
Title: Re: Question - Parameter 'user' not found.
Post by: valdir.marcos 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;
Title: Re: Question - Parameter 'user' not found.
Post by: valdir.marcos 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.
Title: Re: Question - Parameter 'user' not found.
Post by: Zvoni 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;
Title: Re: Question - Parameter 'user' not found.
Post by: kholyphoenix1 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