Pascal noob needs assistance with Running DB Query with Params from TDBGridCell lazarus / 16-Databases ---------------------------------------------------------------------- funk247 · 2013-07-23 16:38 I'm sure the title says it all, I've setup a simple form with a DBGrid, relevant DB Connection/Transaction and Sources and added a couple of query items. The Query to pull in the Initial list works fine, and I've managed to pick out ID's from a hidden column to search against. However I don't think the Params are being passed correctly to my SQL string since I always recieve the error 'Field not found' So Heres my TSQLQuery.SQL.Text: SELECT * FROM table WHERE ID = :AccID If I remove the :AccID reference then the search works normally so it must be the method I'm using to implement Parameters thats at fault :@ I'm trying to pass the contents of a call into it via code in the procedure call, Is there anyway to add the Params into the Object inspector so I can preview results indev? TSQLQuery.Params.ParamByName('AccID').AsString := listAccounts.Fields[0].AsString; ---------------------------------------------------------------------- LacaK · 2013-07-24 05:33 Can you please show to us any code snippet which will better demonstrate error? ---------------------------------------------------------------------- funk247 · 2013-07-24 10:20 Yeah sorry about that, my post was a bit obtuse, had been trying to get this supposedly simple function working for 2 days and was experiencing major code burn. My whole procedure code was: Code: [Select]procedure TForm1.TDBGridCellClick(Column: TColumn);   begin   selected := listAccounts.Fields[0].AsString;   // accSelect.SQL.Text := 'SELECT * FROM tbl_accounts WHERE tbl_accounts.ClientID = 2';   accSelect.Params.ParamByName('AccID').AsString := selected;   textEdit.Text := accSelect.FieldByName('AccountNumber').AsString; end; I found out what the issue was though! I needed to close the query before defining the Params and then re-open it! Where was that snippet of info in the Lazarus documentation!? I'd never have got it working! Learning off the internet is like trying to bring down an eagle with a stone, full of missed opportunities! Anyway heres the working code: Code: [Select]procedure TForm1.TDBGridCellClick(Column: TColumn);   begin     selected := listAccounts.Fields[0].AsString;     accSelect.Close;     accSelect.Params.ParamByName('AccID').AsString := selected;     accSelect.Open;     // Can update Field text now     accNumEdit.Text := accSelect.FieldByName('AccountNumber').AsString;   end; I will say that despite my moaning I'm really enjoying learning how to use Lazarus, its a very useful tool. ---------------------------------------------------------------------- sylvanus67 · 2013-07-24 10:58 Maybe Code: [Select] with ZQuery do     begin       Close;       SQL.Clear;       SQL.Add('select * from database ');       SQL.Add('where field1= :para');       ParamByName('parad').AsInteger := something;       execsql;     end;