Solved

syntax error in FROM clause

Posted on 2001-08-25
4
402 Views
Last Modified: 2010-04-06
hi,

i have a combo filled via ado's gettablenames
and onchange event of combo looks like:

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
AdoTable1.Active := False;
AdoTable1.TableName := Combobox1.text;
DbMemo1.Datafield := Combobox1.Text + ' Code';
DbMemo2.Datafield := Combobox1.Text + ' Title';
AdoTable1.Active := True;
etc...


problem arises when a table name is stupid like
c++
 or
tablename with spaces
etc..

im getting a "syntax error in FROM clause" error .

i understand i could normally use quotes in a
sql statement to get around these sort of problems but
i dont know how to do it for this scenario ..is there a quick fix i can do for this?

as a last resort i can change the tablenames but id rather not ;-)

Regards Barry
0
Comment
Question by:inthe
  • 2
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 6424710
just doublequote the tablename like "c++"

AdoTable1.TableName := '"'+Combobox1.text+'"';

0
 
LVL 17

Author Comment

by:inthe
ID: 6424736
hi meikl,
i tried that one first ;-)
it gives syntax error in query error.

but you lead me to right idea:

AdoTable1.TableName := '['+Combobox1.text+']';

i never tried that one i was trying using "" and ()..

cheers Barry

while im here another piece of code looks like :

  AdoQuery1.SQL.Clear;
  AdoQuery1.SQL.Add
  ('SELECT * FROM '+combobox1.text+' WHERE '+Edit1.Text+' IN '+combobox1.text+'.['+combobox1.text + ' Code]');
  AdoTable1.DisableControls;
  edit1.text := AdoQuery1.SQL.Text;
   Adoquery1.ExecSQL;
  ADOTable1.EnableControls;

a bit messy i know but the sql ends up as:

SELECT * FROM Application WHERE shell IN Application.[Application Code]

which produces the following exact error:

in operator without () in query expression
 'shell IN Application.[Application Code]'

do you know what the sql should end up like for that to work?

i did have it working on simple tablenames but again when i came to a table with a break in name etc it died so i had to start the []()"" stuff :-)
0
 
LVL 17

Author Comment

by:inthe
ID: 6424743
just to clarify the [] did work to solve original problem:

AdoTable1.TableName := '['+Combobox1.text+']';


0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6424835
oh, this jetsql-syntax :-(

well, thanks for the points, :-))
glad to adviced you to the right way,
even i was not correct by this chars []

meikl ;-)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question