Solved

syntax error in FROM clause

Posted on 2001-08-25
4
403 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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Virtuailstring tree add node to another virtuailstring tree list 4 120
can't find the executable in Simulator 1 101
SUM 2 INTEGER ARRAYS INTO 1 10 108
Dev express lookupcombo 3 35
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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