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?