1

Please help me to understand what is happening. Suppose there are following items in an Access database:

table MyTable: IDLine (auto-increment field), a, b (integers), and there is a line with IDLine = 4 in this table.

query MyQuery:

 SELECT IDLine, a+b AS Sum
 FROM MyTable
 WHERE IDLine >= :MinLine;

- i.e. a query that counts some statistics for MyTable and also selects some lines using a parameter.

Then in Delphi a TADOQuery is created:

SELECT *
FROM MyQuery
WHERE IDLine = :IDLine;

and the program is as follows:

ADOQuery1.Close;
ADOQuery1.Parameters.ParamByName('MinLine').Value := 2;
ADOQuery1.Parameters.ParamByName('IDLine').Value := 4;
ADOQuery1.Open;
ShowMessage(IntToStr(ADOQuery1.RecordCount));

For some reason the message gives 0, but there should be 1 line. Why is this happening?

If I change the text of ADOQuery1 to

SELECT *
FROM MyQuery
WHERE IDLine = 4;

the message gives 1. Also, if I delete the last line (with MinLine parameter) from MyQuery in Access, the message gives the proper result as well - does this mean that the problem is somehow connected with the parameter? But I can't get rid of the MinLine parameter in MyQuery, in fact this is just a subquery of an INSERT-INTO construction. What am I doing wrong and how can I solve this problem?

  • 1
    Im not sure what is going on, but the order of the parameters seems to have influence here. MinLine as first parameter and IDLine works for me, IDLine as first and MinLine as Second does not. – bummi Jul 07 '14 at 14:51
  • 1
    It will prompt or need MinLine and then IDLine, that's logical. MyQuery will be executed first, its paramater is needed first and then TADOQuery. If you keep the sequence of parameters MinLine, IDLine, are you getting result ? or any error/problem ? – Sham Yemul Jul 08 '14 at 04:40
  • @bummi Thank you! It works. The question is closed. – livin-in-daylight Jul 08 '14 at 09:00

1 Answers1

0

The problem is solved by means of changing the order of the parameters to MinLine, then IDLine. Thank you for the answers.