Forum > Database

Error Insert TSQLQuery Component (SOLVED)

(1/3) > >>

Root2:
Dear community, please could you help me with an error that I get when saving data, I am using the component "TSQLQuery" the code is this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button4Click(Sender: TObject);begin  SQLQuery1.Close;  SQLQuery1.Clear;  SQLQuery1.SQL.Add('insert into tdtag (dirtag,valtagint,nametag,typedata)');  SQLQuery1.SQL.Add('values (:dirtag,:valtagint,:nametag,:typedata)');    SQLQuery1.ParamByName('dirtag').AsInteger:=PLCTagNumber1.MemAddress;  SQLQuery1.ParamByName('valtagint').AsFloat:=PLCTagNumber1.Value;    SQLQuery1.ParamByName('nametag').AsString:=PLCTagNumber1.Name;  SQLQuery1.ParamByName('typedata').AsString:='I';    SQLQuery1.Open;end; 
When I compile it doesn't give any error, but when I press on the save button I get this message:

"the project has thrown exception epqdatabaseerror preparation query failed, no parameter $1 line 3 values ($1,$2,$3)"

thank you very much for your time and attention.

Root2:
I found this example:

https://lists.lazarus-ide.org/pipermail/lazarus-es/2009-September/001358.html

I have adjusted it to my requirement, it doesn't give me any error, but when I press the save button it does nothing, it doesn't save.
This is the code:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button4Click(Sender: TObject);var  consulta: String;begin  consulta:='insert into tdatostag (dirtag,valortagint,nombretag,tipodato) values (:dirtag,:valortagint,:nombretag,:tipodato)';  SQLQuery1.Close;  SQLQuery1.SQL.Clear;  SQLQuery1.SQL.Add(consulta);  with SQLQuery1.Params do begin        ParamByName('dirtag').AsInteger:=PLCTagNumber1.MemAddress;        ParamByName('valortagint').AsFloat:=PLCTagNumber1.Value;        ParamByName('nombretag').AsString:=PLCTagNumber1.Name;        ParamByName('tipodato').AsString:='F';  end;  SQLQuery1.ExecSQL;end; 
Thank you very much for your kind attention.

Best regards.

rvk:

--- Quote from: Root2 on June 27, 2022, 07:11:45 pm ---I have adjusted it to my requirement, it doesn't give me any error, but when I press the save button it does nothing, it doesn't save.

--- End quote ---
How do you know nothing is saved? I don't see any reading of records here.

Also, how are you handling transaction (and what db are you using etc).
If the transaction isn't handled it could be rolled back at the end if your program, removing any changes you made.

dseligo:
What rvk said is correct, so check that.

I just want to say that in your first example you should have 'ExecSQL' instead of 'Open', like this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button4Click(Sender: TObject);begin  SQLQuery1.Close;  SQLQuery1.Clear;  SQLQuery1.SQL.Add('insert into tdtag (dirtag,valtagint,nametag,typedata)');  SQLQuery1.SQL.Add('values (:dirtag,:valtagint,:nametag,:typedata)');    SQLQuery1.ParamByName('dirtag').AsInteger:=PLCTagNumber1.MemAddress;  SQLQuery1.ParamByName('valtagint').AsFloat:=PLCTagNumber1.Value;    SQLQuery1.ParamByName('nametag').AsString:=PLCTagNumber1.Name;  SQLQuery1.ParamByName('typedata').AsString:='I';    SQLQuery1.ExecSQL;end;

Root2:
Hi rvk, thanks for replying.

After doing the test I checked in the database with a Select.
I am using PostgreSQL, the SQLTransacction action is caRollBack, the lazarus version is 2.2.2.2, I also include a link to the project in case this helps.

https://we.tl/t-oUHUuc9c2x

Best regards.

Navigation

[0] Message Index

[#] Next page

Go to full version