In addition to the points mentioned in @DavidHeffernan's answer, there are at least four syntax errors in your INSERT statement. Any of these could give rise to the AV you're reported, depending on the type of query component you are using, which you have not stated, or at least cause the INSERT to fail.
In your
qry.SQL.Add('INSERT INTO CompnayList (CompanyID, CompanyName, CompanyNumber, CompanyEmail, ') ;
firstly, presumably CompnayList
should read CompanyList
. I mentioned this in a comment to which you have not replied.
secondly, there should be no comma in the SQL statement after `CompanyEmail'
thirdly there should be a closong parenthesis after `CompanyEmail'
So the corrected version should read
qry.SQL.Add('INSERT INTO Comp**an**yList (CompanyID, CompanyName, CompanyNumber, CompanyEmail)') ;
Next, the SQL in your
qry.SQL.Add('Values (edtCompID.Text, edtCompName.Text, edtCompNumb.Text, edtCompanyEmail.Text') ;
is again missing a closing parenthesis and if you are intending to access the texts of edtCompID
, you are doing it incorrectly and the line should read
qry.SQL.Add('Values (' + edtCompID.Text + ', ' + edtCompName.Text + ', ' + edtCompNumb.Text + ', ' + edtCompanyEmail.Text + ')') ;
As David has said, it is better if you parameterize your SQL statements, but not just because of the risk of SQL-Injection.
Btw, you are making things more error-prone than they need be by using calls to qry.SQL.Add()
to build your SQL statement. This is because the outer parentheses make it more difficult to spot error in the text you are trying to add, especially when the text is supposed to contain parentheses of its own. It is better to use a string variable as a temporary "holder" to receive the SQL as you build it up and then, once it's complete, assign it to the qry's Sql.Text
property like this
var
S : String;
begin
[...]
S := 'select * from mytable';
qry.SQL.Text := S;
qry.Open;
[...]
end;