Operator not applicable to this operand type When filtering a table

Go To StackoverFlow.com

0

i'm trying to filter a table with 2 different filters, so that when a button is pressed the only records displayed are those with a certain Job_ID and those with the Type 'Private'. i have the following code:

if CBSearchType.Text = 'Private' then
begin
DBTravel.DataSource.DataSet.DisableControls;
            DBTravel.DataSource.DataSet.Filtered := False;
            DBTravel.DataSource.DataSet.Filter := ('Job_ID = '+edtAddJobID.Text) AND       ('Type = '+QuotedStr('Private'));
            DBTravel.DataSource.DataSet.Filtered := True;
            DBTravel.DataSource.DataSet.First;
            DBTravel.DataSource.DataSet.EnableControls;
end;

however when i try to compile the error message 'Operator not applicable to this operand type' is displayed, any suggestions? thanks

2012-04-04 16:50
by Alexjjsmith


3

The filter property must be a string

DBTravel.DataSource.DataSet.Filter := Format('(Job_ID =%s) AND (Type=%s)',[edtAddJobID.Text,QuotedStr('Private')]);
2012-04-04 16:56
by RRUZ
Job_ID seems to be numeric and edtAddJobID seems to be an edit field. For improved type safety and user input error handling, use string to Integer conversion, and then use the Integer value in the Format function using %d: (Job_ID = %d) AND ...mjn 2012-04-04 18:31
following the same code ive done the following change
DBTravel.DataSource.DataSet.Filter := Format('(Job_ID =%s) AND (Mode =%s)',[edtAddJobID.Text,edtSearchMode.Text]); With Mode entries being string e.g 'Car','Train'. However when i run the program and enter the Mode and press the button it says that arguments are of the wrong type, what is different - Alexjjsmith 2012-04-04 20:09
When you compare a string field you must quote the string to compare try this : DBTravel.DataSource.DataSet.Filter := Format('(Job_ID =%s) AND (Mode =%s)',[edtAddJobID.Text,QuotedStr(edtSearchMode.Text)]);RRUZ 2012-04-04 20:12
ooh i see, thanks a lot that worke - Alexjjsmith 2012-04-04 20:50


2

I suppose that Filter is a string. Hence, you have to give it a string.

'(Job_ID = ' + edtAddJobID.Text + ') AND (Type = ' + QuotedStr('Private') + ')';
2012-04-04 16:56
by Andreas Rejbrand
Ads