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