Forum > Database

Error Insert TSQLQuery Component (SOLVED)

<< < (2/3) > >>

rvk:

--- Quote from: Root2 on June 27, 2022, 08:16:09 pm ---I am using PostgreSQL, the SQLTransacction action is caRollBack,
--- End quote ---
So, the default action is rollback.

Did you commit the transaction somehow (via button, tdbnavigator) or in code via transaction.commit?

(I did not look at your code yet)

Root2:
dseligo, thanks for replying, I tried that and I get this error: "no parameter $1 values($1,$2,$3,$4)", although when reviewing more in detail the query I found a small error related to the number of columns, I corrected the error however it still gives error, anyway I would like to make the insert work with the second example as that will allow me to insert several records to the same fields which is what I want to do.

Root2:
I think I misunderstood, but I don't think I'm using commit anywhere.

I modified the default action, I set it to caCommit, now the message I get is:
"Cannot open a non-select statement"

Regards.

Root2:
it works, it was only to modify it to be commit, I didn't save correctly, I checked again and it worked, thank you very much.
Now I have a question about this mode, can I save several records at the same time with this mode using the following 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';         ParamByName('dirtag').AsInteger:=PLCTagNumber2.MemAddress;        ParamByName('valortagint').AsFloat:=PLCTagNumber2.Value;        ParamByName('nombretag').AsString:=PLCTagNumber2.Name;        ParamByName('tipodato').AsString:='I';  end;  SQLQuery1.ExecSQL;end; 
all are the same data types.

Thank you very much.

rvk:

--- Quote from: Root2 on June 27, 2022, 09:30:43 pm ---it works, it was only to modify it to be commit, I didn't save correctly, I checked again and it worked, thank you very much.
Now I have a question about this mode, can I save several records at the same time with this mode using the following code?

--- End quote ---
No, but you can do it like this: (each insert needs it's own ExecSQL)


--- 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);   SQLQuery1.ParamByName('dirtag').AsInteger := PLCTagNumber1.MemAddress;  SQLQuery1.ParamByName('valortagint').AsFloat := PLCTagNumber1.Value;  SQLQuery1.ParamByName('nombretag').AsString := PLCTagNumber1.Name;  SQLQuery1.ParamByName('tipodato').AsString := 'F';  SQLQuery1.ExecSQL;   SQLQuery1.ParamByName('dirtag').AsInteger := PLCTagNumber2.MemAddress;  SQLQuery1.ParamByName('valortagint').AsFloat := PLCTagNumber2.Value;  SQLQuery1.ParamByName('nombretag').AsString := PLCTagNumber2.Name;  SQLQuery1.ParamByName('tipodato').AsString := 'I';  SQLQuery1.ExecSQL; end; 
(I don't like the with-statement that much but you could leave it in if you like it more)
You can ommit the extra .Params. because TSQLQuery also has the ParamByName function.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version