Reputation: 1
For my Delphi app with an SQLite database I am using TFDQuery
, TFDConnection
, TDataSource
and TDBGrid
components. All fields except AllKeys
are VARCHAR
. AllKeys
is TEXT
. Everything is connected properly and I can see all records from the database table in the TDBGrid
after I compile and start the application. But when I try to INSERT
into the database table I get:
[FireDAC][Phys][SQLite]ERROR: near "something" syntax error
Code to add a new record:
procedure TForm1.Button4Click(Sender: TObject);
begin
if (cxRichEdit2.text <> '') and (cxTextEdit2.Text <> '') and (cxTextEdit3.Text <> '') then
begin
// adding data into table
FDQuery1.sql.Text := 'INSERT INTO tblTags (Group, Title, Keys, AllKeys) VALUES (:group, :title, :keys, :allkeys)';
FDQuery1.ParamByName('group').asString := ComboBox1.Text;
FDQuery1.ParamByName('title').asString := cxTextEdit2.Text;
FDQuery1.ParamByName('keys').asString := cxTextEdit3.Text;
FDQuery1.ParamByName('allkeys').asString := cxRichEdit2.Text;
FDQuery1.ExecSQL;
end
else
ShowMessage('Please fill all important fields!');
end;
Upvotes: -1
Views: 134
Reputation: 1
I didn't put the fields of the table between quotes " "
. This is the working code:
FDQuery1.sql.Text := 'INSERT INTO tblTags ("Group", "Title", "Keys", "AllKeys") VALUES (:group, :title, :keys, :allkeys)';
FDQuery1.ParamByName('group').asString := ComboBox1.Text;
FDQuery1.ParamByName('title').asString := cxTextEdit2.Text;
FDQuery1.ParamByName('keys').asString := cxTextEdit3.Text;
FDQuery1.ParamByName('allkeys').asString := cxRichEdit2.Text;
FDQuery1.ExecSQL;
Upvotes: 0
Reputation: 416
I don't know CxRichedit but if it behaves like VCL RichEdit I think you have to write
FDQuery1.ParamByName('allkeys').asString := cxRichEdit2.lines.Text;
Upvotes: 0