Solved

syntax error in FROM clause

Posted on 2001-08-25
4
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month3 days, 17 hours left to enroll

630 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