Recent

Author Topic: (SOLVED) error 'SQL statement not set' with INSERT INTO  (Read 153 times)

jex

  • New Member
  • *
  • Posts: 23
(SOLVED) error 'SQL statement not set' with INSERT INTO
« on: April 09, 2020, 08:30:18 am »
Could someone tell me what is wrong with this code?
Using SQLite3

on button click:
Code: Pascal  [Select][+][-]
  1.  
  2. try
  3.      //SQLQueryUsrRegister.Close;
  4.      //SQLQueryUsrRegister.SQL.Clear;
  5.      SQLQueryUsrRegister.Open;
  6.      SQLTransUsrRegister.Action := caCommit;
  7.      //SQLTransUsrRegister.Active := True;
  8.      SQLQueryUsrRegister.SQL.Add('INSERT INTO UserAccounts (UsrName, UsrPass, UsrEmail)VALUES(:USERNAME, :USERPASSWORD, :USEREMAIL)');
  9.      SQLQueryUsrRegister.Params.ParamByName('USERNAME').AsString := txtUsername.Text;
  10.      SQLQueryUsrRegister.Params.ParamByName('USERPASSWORD').AsString := txtPassword.Text;
  11.      SQLQueryUsrRegister.Params.ParamByName('USEREMAIL').AsString := txtEmail.Text;
  12.      SQLQueryUsrRegister.ExecSQL;
  13.      //SQLQueryUsrRegister.Active := True;
  14.      //SQLQueryUsrRegister.Insert;
  15.      //SQLQueryUsrRegister.ApplyUpdates;
  16.      SQLiteUsrRegister.Transaction.CommitRetaining;
  17.      //SQLQueryUsrRegister.Transaction.ExecuteAction();
  18.      SQLTransUsrRegister.Commit;
  19.                                  

on formCreate:
Code: Pascal  [Select][+][-]
  1. SQLiteUsrRegister.Connected := False;
  2.    SQLiteUsrRegister.DatabaseName := SysUtils.ExtractFilePath(ParamStr(0)) + 'sqlite.db';
  3.    SQLiteUsrRegister.Connected := True;
  4.  
  5.    if SQLiteUsrRegister.Transaction.Active = False
  6.    then SQLiteUsrRegister.Transaction.StartTransaction;


I've been searching and tested other stuff but none helped, also  tested with the commented lines.

Thank you
« Last Edit: April 09, 2020, 08:54:43 am by jex »

jex

  • New Member
  • *
  • Posts: 23
Re: error 'SQL statement not set' with INSERT INTO
« Reply #1 on: April 09, 2020, 08:54:02 am »
Nevermind, got it working with the following code (ignore commented).

Code: Pascal  [Select][+][-]
  1. //SQLQueryUsrRegister.Open;
  2.      SQLTransUsrRegister.Action := caCommit;
  3.      //SQLTransUsrRegister.Active := True;
  4.      SQLQueryUsrRegister.SQL.Text := ('INSERT INTO UserAccounts (UsrName, UsrPass, UsrEmail)VALUES(:USERNAME, :USERPASSWORD, :USEREMAIL)');
  5.      SQLQueryUsrRegister.Params.ParamByName('USERNAME').AsString := txtUsername.Text;
  6.      SQLQueryUsrRegister.Params.ParamByName('USERPASSWORD').AsString := txtPassword.Text;
  7.      SQLQueryUsrRegister.Params.ParamByName('USEREMAIL').AsString := txtEmail.Text;
  8.      //SQLQueryUsrRegister.Active := True;
  9.      //SQLTransUsrRegister.StartTransaction;
  10.      SQLQueryUsrRegister.ExecSQL;
  11.      //SQLQueryUsrRegister.Active := True;
  12.      //SQLQueryUsrRegister.Insert;
  13.      //SQLQueryUsrRegister.ApplyUpdates;
  14.      //SQLiteUsrRegister.Transaction.CommitRetaining;
  15.      //SQLQueryUsrRegister.Transaction.ExecuteAction();
  16.      SQLTransUsrRegister.Commit;
  17. [code]
  18.  
  19.  

 

TinyPortal © 2005-2018