0

I have the following procedure which is executed on a button click (button1). After being prompted to log into the database, delphi throws the the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''AlphaMc'

SELECT * FROM 'AlphaMc111'' at line 1'. Process Stopped. Use Step or Run to continue.

Here is the procedure:

procedure TMainWin.Button1Click(Sender: TObject);
begin
  ADOConnection1.ConnectionString := 'Driver={MySQL ODBC 3.51 Driver};
  Server=db4free.net;Port=3306;Database=inventmanager;User=******;
  Password=******;Option=3;';

  ADOConnection1.Connected := True;
  ADOQuery1.Connection := ADOConnection1;

  ADOQuery1.SQL.Add('SELECT * FROM ''AlphaMc111''');
  ADOQuery1.Open;
end;

3 Answers 3

1

Don't use quotes to escape column or table names. Use backticks

ADOQuery1.SQL.Add('SELECT * FROM `AlphaMc111`');

Quotes are string delimiters.

Sign up to request clarification or add additional context in comments.

Comments

1

I think the Problem is the Query itself.

AlphaMc111 does not need to be quoted as it is a Tablename

Quoted strings are only needed for Textinput in SQL Syntax.

try

ADOQuery1.SQL.Add('SELECT * FROM AlphaMc111'));

Comments

0

The MySql identifier quote character is the backtick, try

ADOQuery1.SQL.Add('SELECT * FROM `AlphaMc111`');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.