Reputation: 47
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;
Upvotes: 0
Views: 894
Reputation: 687
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'));
Upvotes: 1
Reputation: 5518
The MySql identifier quote character is the backtick, try
ADOQuery1.SQL.Add('SELECT * FROM `AlphaMc111`');
Upvotes: 0
Reputation: 204924
Don't use quotes to escape column or table names. Use backticks
ADOQuery1.SQL.Add('SELECT * FROM `AlphaMc111`');
Quotes are string delimiters.
Upvotes: 1