I want to apply multiple conditions in Datatable.Select query how can I do this.
Below is the code that I have:
dvOrg.Table.Select("customer_type_id='64501'", "sort_column");
Now I want to apply one more condition covered_patient_type='Inpatient'
.
I tried this but it did not work.
dvOrg.Table.Select("customer_type_id='64501' and covered_patient_type='Inpatient'", "sort_column");
Please help.
Thanks in advance.
2
Answers
The code for this is correct, which means the problem will be related to the specific data schema and the data types.
This fiddle proves the concept, selecting by multiple columns is similar to SQL WHERE clause, using
AND
to append additional column criteria. In this OP is correct.https://dotnetfiddle.net/7cPr5H
This works only if the
covered_patient_type
is implicitly castable to a string.For this data, we can see that
customer_type_id
is an int, but in the filter we can expect it to be a string and the filter condition still works:The common scenario where this isn’t straight forward are when
covered_patient_type
is stored as an integer (or some other type where the value is a reference to another list, or enum and you are resolving the visible value in the view.In that case you need to filter on the underlying value, if
"Inpatient"
in the view is an enum, cast it to an int, or if"Inpatient"
is a vlaue from a related table or otherwise unreleated list, resolve the pointer value that matches the value used int underlying DataTable dataset.If your code still doesn’t work, try building up the filter by adding conditions one by one.
And just double-check whether your data types are in the correct form.