0

I am trying to insert a new record into my database using SQL, but it keeps telling me that I have a syntax error in the from clause.

I don't see the error.

Here is the code:

procedure TForm1.BitBtn7Click(Sender: TObject);
var
 sCategoryName :string;
begin
 sCategoryName := InputBox('Category Name', 'Please enter your category name that you would like to add','');
 with dmRecords do
  begin
   qryRecords.Active := False;
   qryRecords.SQL.Add('INSERT INTO [Category of Income]([Category Name])');
   qryRecords.SQL.Add('VALUES ' + '(' + QuotedStr(sCategoryName) + ')');
   qryRecords.ExecSQL;
   qryRecords.SQL.Add('SELECT * FROM [Category of Income] ORDER BY [Category ID]');
   qryRecords.Active := True;
  end; 
end;
1
  • 1
    As a sidenote, please stop using concatenated SQL statements, use parameters instead. You are vulnerable to SQL injection. Commented Oct 9, 2015 at 12:18

1 Answer 1

1

You haven't cleared the SQL from the previous statement. When you open the query, SQL has three lines of text.

Add qryRecords.SQL.Clear before adding the SELECT statement.

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

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.