Solved

syntax error in FROM clause

Posted on 2001-08-25
4
398 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now