How to pass parameter to query using dbExpress in Delphi

I want to use the dqExpress TSQLQuery component. But I do not know how to write SQL to add a parameter. I will give an example, maybe it will be more clear what my problem is.

The following works in TADOQuery:

SELECT* FROM sometable WHERE sometable.id = :value; 

Now in the above example, you pass the parameter to the query using a colon (:) before the parameter name. But when I try to do this with TSQLQuery, I get the following error:

 dbExpress driver does not support the TDBXTypes.UNKNOWN data type. Vendor Error Message. 

Now, if this is not the case as you pass the parameter in the TSQLQuery component, can someone please help me. This is a new territory for me.

Im using the Firebird database, and Im using Delphi XE2

+4
source share
1 answer

To set parameter properties, you must use the Params property. From here, you can access each parameter using an index or name to set the value of the parameter using one of the properties AsString , AsInteger, and so on, depending on the type of field.

Check out this sample.

 var LSQLQuery : TSQLQuery; begin LSQLQuery:=TSQLQuery.Create(nil); try LSQLQuery.SQLConnection:=SQLConnection1; LSQLQuery.CommandText:='Select FIRST_NAME from EMPLOYEE Where EMP_NO=:Param1'; LSQLQuery.Params.ParamByName('Param1').AsInteger:=2;//or using the index of the parameter LSQLQuery.Params[0].AsInteger:=2; LSQLQuery.Open;//Execute the query ShowMessage(LSQLQuery.FieldByName('FIRST_NAME').AsString); //get the data LSQLQuery.Close; finally LSQLQuery.Free; end; end; 
+8
source

All Articles