TMyQuery and ParamByName
Posted: Sun 14 Feb 2021 18:26
I'm trying to build a dynamic query where the user can select the field as part of the search.
My question is can I do this by using ParamByName?
Example :
MyQuery1.SQL := 'select * from mytable where :field = :value;'
MyQuery1.ParamByName('field').AsString := 'fieldname';
MyQuery1.ParamByName('value').AsString := 'myvalue';
MyQuery1.Execute;
The test didn't return any errors but it didn't return any results either when I reference MyQuery1.RecordCount , so I'm guessing it doesn't necessarily work this way, but if it does, what am I doing wrong? Or is there an easier way to do it? If so, could an example be provided?
My question is can I do this by using ParamByName?
Example :
MyQuery1.SQL := 'select * from mytable where :field = :value;'
MyQuery1.ParamByName('field').AsString := 'fieldname';
MyQuery1.ParamByName('value').AsString := 'myvalue';
MyQuery1.Execute;
The test didn't return any errors but it didn't return any results either when I reference MyQuery1.RecordCount , so I'm guessing it doesn't necessarily work this way, but if it does, what am I doing wrong? Or is there an easier way to do it? If so, could an example be provided?