Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Select statement with params
Wed, Apr 4 2007 2:09 AMPermanent Link

Alfred Ghazzi
Hi

The following code does not work

Query.sql.Clear;
Query.sql.Add('SELECT * FROM Table1 WHERE ID = :ID');
Query.ParamByName('ID').Value := 5;
Query.Active := True;
Query.RecordCount = 0; // It is wrong. This statement should have returned 1; there is one record with id = 5

But if I ignore the params and insert 5 directly into the select statement , it works...

Query.sql.Clear;
Query.sql.Add('SELECT * FROM Table1 WHERE ID = 5');
Query.Active := True;
Query.RecordCount = 1 // Which is correct

Using EDB 1.01 Build 1, D2006 and WinXP

Please advise me

Many thanks
Wed, Apr 4 2007 5:29 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Alfred,

<< The following code does not work

Query.sql.Clear;
Query.sql.Add('SELECT * FROM Table1 WHERE ID = :ID');
Query.ParamByName('ID').Value := 5;
Query.Active := True;
Query.RecordCount = 0; // It is wrong. This statement should have returned
1; there is one record with id = 5 >>

What data type is the 'ID' parameter set to ?  Or is it not set ?  What
happens if you use this line instead:

Query.ParamByName('ID').AsInteger := 5;

?

--
Tim Young
Elevate Software
www.elevatesoft.com

Wed, Apr 4 2007 8:50 PMPermanent Link

Alfred Ghazzi
Hi Tim

Thanks for the reply

The param is integer. I used the following code

   EDBQuery1.ParamByName('CID').DataType := ftInteger;
   EDBQuery1.ParamByName('CID').ParamType := ptInput;
   EDBQuery1.ParamByName('CID').AsInteger := 5;
   EDBQuery1.Active := True;

unfortunately it did not work.

To test it in its most basic form. I createed a form, dropped session, database, query, datasource, and dbgrid objects. I connected the objects and
set the sql in the query object to 'SELECT * FROM components WHERE ID = :ID'. Then in object inspecter I clicked on Params and I found one
param named ID, I set its datatype to Integer and paramtype to Input (I have done it also without setting paramtype, just leave it as is). I set the
active property of the query object to True. Now the grid shows all the column titles but no data record. I modified the SQL statement and
replaced :ID with 5, set active to true, the grid shows record with id 5.

Many thanks
Image