1

I am writing a script using Pascal in our ERP system.

I am connecting to a MS Access database which has two tables. TIMESHEETHEADER and TIMESHEETLINES.

I have a query that is reading from the database. I would like to pass some variables to the query, but not entirely sure how.

If I have the sql:

ADOQRY.SQL.ADD('select FIRSTNAME, LASTNAME from TIMESHEETHEADER where LASTNAME = :LASTNAME');
ADOQRY.PN('LASTNAME') := EMP_LASTNAME;

I have also tried:

ADOQRY.Parameters.ParamByName('EMP_LASTNAME');

I get a error during compiling which is "Undeclared identifier:'PN' at 156:17" (156:17 represents the line number and number of characters in from the left)

I can get it working with the following: ADOQRY.SQL.ADD('select FIRSTNAME, LASTNAME from TIMESHEETHEADER where LASTNAME = ' + EMP_LASTNAME ); But I don't think that is the best way of doing it. I believe it could be compromised via SQL injection.

I use the following to declare the connection:

 ADO.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + TimeSheetFolder + 'TimeSheetRecharge.mdb';
 ADO.LoginPrompt := False;
 ADO.Connected := true;
 ADOQry.Connection := ADO;

I have no problem when accessing a firebird database.

What is the correct syntax for passing a parameter to the SQL query?

Simon King
  • 165
  • 2
  • 17
  • Does this answer your question? [How to pass string parameters to an TADOQuery?](https://stackoverflow.com/questions/15989265/how-to-pass-string-parameters-to-an-tadoquery) – June7 Dec 06 '22 at 18:20
  • The above post from about 10 years ago should work. I am doing the same thing, but it doesn't work. I get an error "Could not convert variant of type null into type integer at ###:##" But no where do I declare the data type of 'batchno' so how would there be an error? BatchNumber is declared as type Integer. I tried converting the integer to a string with `:=inttostr(BatchNumber);` but got the same error. The cursor says the error is between parambyname and (. My SQL query is `ADOUpdateQry.SQL.Add('Update TIMESHEETLINES set BATCHNO= :batchno where ID= :id');` – Simon King Dec 06 '22 at 21:17

0 Answers0