Search code examples
sqldelphidelphi-2010

How use the insert query using parameters?


When i try with this query i get an error says that Perameter email doesn't exist, i am sure that the variables : email, login_pass, payment_method,operateur are valid and exists.

SQLQuery2.sql.Text := 'INSERT INTO registered (email,login_pass,payment_method,operateur) VALUES (":email",":login_pass",":payment_method",":avecpuce")';
SQLQuery2.ParamByName('email').AsString := email;
SQLQuery2.ParamByName('login_pass').AsString := login_pass;
SQLQuery2.ParamByName('payment_method').AsString := payment_method;
SQLQuery2.ParamByName('avecpuce').AsString := avecpuce;
SQLQuery2.ExecSQL(true);

I tried removing the quotation, but i get

You have an error in your Sql syntax, check the manual that corresponds to your SQL server for the right syntax to use near ':email,:login_pass,:payment_method,:avecpuce)' at line 1

How to use the insert query above using parameters?


Solution

  • Found the answer !

    MySQLQuery2.SQL.Clear;
    MySQLQuery2.SQL.Add('INSERT INTO COUNTRY (NAME, CAPITAL, POPULATION)');
    MySQLQuery2.SQL.Add('VALUES (:Name, :Capital, :Population)');
    MySQLQuery2.Params[0].AsString := 'Lichtenstein';
    MySQLQuery2.Params[1].AsString := 'Vaduz';
    MySQLQuery2.Params[2].AsInteger := 420000;
    MySQLQuery2.ExecSQL;
    

    Thankyou All !!