Board index » delphi » "Missing comma" error with SQL statement

"Missing comma" error with SQL statement

My student is trying to UPDATE a STUDENT database using the following SQL
statement:
        with UpdQuery do begin
                Close;
                with SQL do begin
                        Clear;
                        Add ('UPDATE STUDENT');
                        Add ('SET StudentID = :StudentID,');
                        Add ('StudentName = :StudentName');
                        Add ('WHERE StudentID = :StudentID');
                end;
                Open;
                ExecSQL
        end;

The error is "Missing comma     Field :StudentID. Table: Student. Image: 2.

 

Re:"Missing comma" error with SQL statement


Quote
wsumm...@venus.nmhu.edu (Computer Science) wrote:
>My student is trying to UPDATE a STUDENT database using the following SQL
>statement:
>        with UpdQuery do begin
>                Close;
>                with SQL do begin
>                        Clear;
>                        Add ('UPDATE STUDENT');
>                        Add ('SET StudentID = :StudentID,');
>                        Add ('StudentName = :StudentName');
>                        Add ('WHERE StudentID = :StudentID');
>                end;
>                Open;
>                ExecSQL
>        end;

>The error is "Missing comma     Field :StudentID. Table: Student. Image: 2.

You need to delete the Open Line in your program.  The ExecSQL is the
only thing you need for a query that doesn't return any data.  Use
Open for anything that does return data

Brad Huggins

Re:"Missing comma" error with SQL statement


If that is all the code you have, then you need to supply Paramaters to
the variables referenced in the Sql.  Before opening and executing the
query, add the following lines :

ParamByName('StudentId').AsString := Edit1.text;{Whatever variable is
used}
ParamByName('StudentName').AsString := Edit2.text;

Re:"Missing comma" error with SQL statement


Quote
>My student is trying to UPDATE a STUDENT database using the following SQL
>statement:
>        with UpdQuery do begin
>                Close;
>                with SQL do begin
>                        Clear;
>                        Add ('UPDATE STUDENT');
>                        Add ('SET StudentID = :StudentID,');
>                        Add ('StudentName = :StudentName');
>                        Add ('WHERE StudentID = :StudentID');
>                end;
>                Open;
>                ExecSQL
>        end;
>The error is "Missing comma     Field :StudentID. Table: Student. Image: 2.

Without even testing it, your query is not logical.  

1) the 'set StudentID =:StudentID' serves no purpose when you have
specified 'where StudentID =:StudentID'.  

2) You can't OPEN a query that doesn't produces a cursor.  You must
use EXECSQL.

Try this:

with UpdQuery, UpdQuery.SQL do begin
  Close;
  Clear;
  Add ('UPDATE STUDENT');
  Add ('SET StudentName = :StudentName');
  Add ('WHERE StudentID = :StudentID');
  { Set parameters here }
  ExecSQL;
end;

Also, if you are not using the TQuery component for any other purpose,
set the SQL property at design time.

Wade

Other Threads