Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Syntax error. in query expression


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Oct 22, 2017 11:54 PM Last Post By: edward paul
fiaz ahmad

Posts: 3
Registered: 9/7/17
Syntax error. in query expression  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 7, 2017 12:23 AM
I have following query and face error and my Using XE8 with MS Access

Syntax error. in query expression 'select CCarID from tcustomercar where Car = (LX008)'

Procedure TFNewCarAct.BtnSaveClick(Sender: TObject);
begin
adoQueryCCA.Close();
adoQueryCCA.SQL.Clear;
adoQueryCCA.SQL.Add('INSERT INTO tcustomercaractivity ([CCarID],[Date],[Millage],[SerRcd],[EOType],[EOQunt],[AirFil],[GOil])');
adoQueryCCA.SQL.Add('values (select CCarID from tcustomercar where Car = ('+ComboBox2.Text+'))');
adoQueryCCA.SQL.Add('VALUES(:Date,:Millage,:SerRcd,:EOType,:EOQunt,:AirFil,:GOil)');
adoQueryCCA.Parameters.ParamByName('Date').Value:= Edit6.Text;
adoQueryCCA.Parameters.ParamByName('Millage').Value:= Edit1.Text;
adoQueryCCA.Parameters.ParamByName('SerRcd').Value:= memo1.Text;
adoQueryCCA.Parameters.ParamByName('EOType').Value:= Edit2.Text;
adoQueryCCA.Parameters.ParamByName('EOQunt').Value:= Edit3.Text;
adoQueryCCA.Parameters.ParamByName('AirFil').Value:= Edit4.Text;
adoQueryCCA.Parameters.ParamByName('GOil').Value:= Edit5.Text;
adoQueryCCA.ExecSQL;
ShowMessage('All Done');
end;

Edited by: fiaz ahmad on Aug 7, 2017 12:24 AM
William Tucker

Posts: 14
Registered: 12/17/09
Re: Syntax error. in query expression [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 7, 2017 7:06 AM   in response to: fiaz ahmad in response to: fiaz ahmad
fiaz ahmad wrote:

I have following query and face error and my Using XE8 with MS Access

Syntax error. in query expression 'select CCarID from tcustomercar
where Car = (LX008)'

You are going to need quotation marks around the value LX008 or a
parameter, not parenthesis. Also, I think you should have only one
values clause, not two.

Why aren't you passing ComboBox2.Text as a parameter like the others
instead of directly injecting it into the statement? See
https://en.wikipedia.org/wiki/SQL_injection.

The resulting statement should look like:
INSERT INTO tcustomercaractivity
([CCarID],[Date],[Millage],[SerRcd],[EOType],[EOQunt],[AirFil],[GOil])
VALUES ((SELECT CCarID FROM tcustomercar WHERE Car =
:Car),:Date,:Millage,:SerRcd,:EOType,:EOQunt,:AirFil,:GOil);

The above statement was not tested; but, I believe it to be what you
want.

William
fiaz ahmad

Posts: 3
Registered: 9/7/17
Re: Syntax error. in query expression  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 7, 2017 8:55 AM   in response to: fiaz ahmad in response to: fiaz ahmad
fiaz ahmad wrote:
I have following query and face error and my Using XE8 with MS Access

Syntax error. in query expression 'select CCarID from tcustomercar where Car = (LX008)'

Procedure TFNewCarAct.BtnSaveClick(Sender: TObject);
begin
adoQueryCCA.Close();
adoQueryCCA.SQL.Clear;
adoQueryCCA.SQL.Add('INSERT INTO tcustomercaractivity ([CCarID],[Date],[Millage],[SerRcd],[EOType],[EOQunt],[AirFil],[GOil])');
adoQueryCCA.SQL.Add('values (select CCarID from tcustomercar where Car = ('+ComboBox2.Text+'))');
adoQueryCCA.SQL.Add('VALUES(:Date,:Millage,:SerRcd,:EOType,:EOQunt,:AirFil,:GOil)');
adoQueryCCA.Parameters.ParamByName('Date').Value:= Edit6.Text;
adoQueryCCA.Parameters.ParamByName('Millage').Value:= Edit1.Text;
adoQueryCCA.Parameters.ParamByName('SerRcd').Value:= memo1.Text;
adoQueryCCA.Parameters.ParamByName('EOType').Value:= Edit2.Text;
adoQueryCCA.Parameters.ParamByName('EOQunt').Value:= Edit3.Text;
adoQueryCCA.Parameters.ParamByName('AirFil').Value:= Edit4.Text;
adoQueryCCA.Parameters.ParamByName('GOil').Value:= Edit5.Text;
adoQueryCCA.ExecSQL;
ShowMessage('All Done');
end;

Edited by: fiaz ahmad on Aug 7, 2017 12:24 AM

Procedure TFNewCarAct.BtnSaveClick(Sender: TObject);
begin
adoQueryCCA.Close();
adoQueryCCA.SQL.Clear;
adoQueryCCA.SQL.Add('INSERT INTO tblcaractivity ([CCarID],[Date],[Millage],[SerRcd],[EOType],[EOQunt],[AirFil],[GOil])');
adoQueryCCA.SQL.Add('VALUES(:CCarID,:Date,:Millage,:SerRcd,:EOType,:EOQunt,:AirFil,:GOil)');
adoQueryCCA.Parameters.ParamByName('CCarID').Value:= Integer(ComboBox2.Items.Objects[ComboBox2.ItemIndex]);
adoQueryCCA.Parameters.ParamByName('Date').Value:= Edit6.Text;
adoQueryCCA.Parameters.ParamByName('Millage').Value:= Edit1.Text;
adoQueryCCA.Parameters.ParamByName('SerRcd').Value:= memo1.Text;
adoQueryCCA.Parameters.ParamByName('EOType').Value:= Edit2.Text;
adoQueryCCA.Parameters.ParamByName('EOQunt').Value:= Edit3.Text;
adoQueryCCA.Parameters.ParamByName('AirFil').Value:= Edit4.Text;
adoQueryCCA.Parameters.ParamByName('GOil').Value:= Edit5.Text;
adoQueryCCA.ExecSQL;
ShowMessage('Done');
end;

edward paul

Posts: 1
Registered: 7/18/15
Access query expression and vba code handling  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2017 11:38 PM   in response to: fiaz ahmad in response to: fiaz ahmad
Well dear…. I don’t have much knowledge on this access query expression, but few days back when I am troubling a lot while working with access VBA code then at least time got the help from this helpful VBA code and VBA functions. So have a look over them, helpful you will also find it workful.
http://www.accessrepairnrecovery.com/blog/microsoft-access-vba-code

ALSO READ:
http://www.accessrepairnrecovery.com/blog/run-access-query-wizard

Edited by: edward paul on Oct 22, 2017 11:54 PM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02