#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    42
    Rep Power
    1

    Getting Parameter not found error with SQLite Insert Query at Delphi XE3


    I am getting error like 'parameter not found' with following SQL query at Delphi

    In table emp
    usergroup_id :- integer
    and
    label, description are string data type.

    My code is as follows

    Code:
            gid: Integer;
            sdescription,ldescription: String;
            SQLQuery31: TSQLQuery;
    
    
            SQLQuery31 := TSQLQuery.Create(nil);
            sdescription := RzEdit1.Text;
            ldescription := RzMemo1.Text;
            gid := Integer(RzComboBox1.Items.Objects[RzComboBox1.Items.IndexOf(gname)]);
    
    
            try
                SQLConnection1.Connected := true;
                SQLMonitor1.Active := True;
                SQLQuery31.SQLConnection := SQLConnection1;
                SQLQuery31.SQL.Text := 'INSERT INTO emp(id, usergroup_id, label, description) VALUES (33,":usergroup_id",":label",":description")';
                SQLQuery31.Params.ParseSQL(SQLQuery31.SQL.Text, True);
                SQLQuery31.Params.ParamByName('usergroup_id').Value := gid;
                SQLQuery31.Params.ParamByName('label').Value := sdescription;
                SQLQuery31.Params.ParamByName('description').Value := ldescription;
                SQLQuery31.ExecSQL;
            except
              on E: EDatabaseError do
                ShowMessage('Exception raised with message' + E.Message);
            end;
    It is giving me an error as 'Parameter usergroup_id not found' if usergroup_id omitted/ignored then 'Parameter Label not found' etc...
    The fields usergroup_id, label, descreiption etc.. all exists in my SQLite table named 'emp' still why I am getting parameters not found error.
    How to sort out this error ?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    Don't put quotes around your parameters...
    Code:
    SQLQuery31.SQL.Text := 'INSERT INTO emp(id, usergroup_id, label, description) VALUES (33,":usergroup_id",":label",":description")';
    should be
    Code:
    SQLQuery31.SQL.Text := 'INSERT INTO emp(id, usergroup_id, label, description) VALUES (33,:usergroup_id,:label,:description)';

    Comments on this post

    • ninadgac agrees
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    42
    Rep Power
    1
    Thanks it sorted out problem...

IMN logo majestic logo threadwatch logo seochat tools logo