Matti G Matti G - 1 year ago 202
Pascal Question

Lazarus Pascal setting value from a textbox

I have to set up some sql queries.

The command I want to enter is


Here is my code

SQLQuery1.SQL.text:=('INSERT INTO tblTest VALUES (' (enterid.text) ')' );

is my textbox that I wish to input a number or name into

How would I get the brackets before and after it to create my command?

Answer Source

I can see two problems with your code. The entire SQL statement is bracketed which is wrong (at least, it's wrong in Delphi, so I assume that it's also wrong in Lazarus. Secondly, the 'values' statement doesn't need the brackets and is liable to store the literal string, "enterid.text".

Better to write like this:

SQLQuery1.SQL.text:= 'INSERT INTO tblTest VALUES (:p1); 
SQLQuery1.params[0].asstring:= enterid.text;
// alternatively SQLQuery1.ParamByName ('p1').asstring:= enterid.text;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download