Asked by:
How to evaluate column expressions without DataTables

Question
-
Hi,
I’m looking for a way to evaluate the column Expression available in ADO.NET … without using a DataTable instance.
Say I have a column expression like iif(a > b, true, false)
Is there a way to evaluate this expression by passing somehow values for a and b?
I looked at the Compute method on DataTable but it is not quite what I’m looking for:
object result1 = new DataTable().Compute("20.0 / 2", null);
object result3 = new DataTable().Compute("iif(10 > 5, true, false)", null);
object result2 = new DataTable().Compute("iif(a > b, true, false)", null); -- how to evaluate this
Idea behind this is to move away from DataTable to simple array structure for performance reason.
Still I need to support a way to generate the legacy expression used.
I would rather avoid building the expression string to generate this as it will be poor performance for large number of rows.
Thanks in advance for your help
Nick
- Moved by Wendy ZangMicrosoft contingent staff Thursday, November 1, 2018 8:40 AM
Wednesday, October 17, 2018 10:57 AM
All replies
-
If expressions are predefined, then you can write
a = …
b = …
result2 = a > b;- Proposed as answer by Wendy ZangMicrosoft contingent staff Thursday, October 18, 2018 7:27 AM
Thursday, October 18, 2018 5:09 AM -
Hi,
Thanks for your response but i don't think it answers the original request.
The expression is defined by user as a string.
So i'm looking for a way to evaluate "iif(a > b, true, false)" in the best possible way.Thanks
Thursday, October 18, 2018 8:27 AM -
Just to be more clear ... expression could be anything ... whatever is supported by ADO.NET column Expression.Thursday, October 18, 2018 8:29 AM
-
Hi dtf017,
According to your feedback, you wanna do what you want in T-SQL.
iif(a > b, true, false)
You could get further help in Transact-SQL forum.
Best Regards,
Wendy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Tuesday, October 23, 2018 7:27 AM