Open viveknuna opened 2 years ago
Tagging subscribers to this area: @roji, @ajcvickers See info in area-owners.md if you want to be subscribed.
Author: | viveknuna |
---|---|
Assignees: | - |
Labels: | `area-System.Data`, `untriaged` |
Milestone: | - |
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
@ajcvickers @roji Above is the complete code, I am again posting with the Main method so that you can just this to any application and reproduce it.
static void Main(string[] args)
{
try
{
string formula = "(Column * 2)";
DataTable dt = new DataTable();
dt.Columns.Add("Column");
string filter = "Column = 1";
var temp = dt.Compute(formula, filter);
}
catch (Exception ex)
{
}
}
In short, I am trying to evaluate a mathematical expression by using DataTable here. so (Column * 2) is an expression, so If the Column value is 3, it should return 6. The above is just an example. It could be a complex expression as well. You can refer to this question to understand
There are some libraries that already do this like Flee and NCalc. But I am avoiding using any external library.
I have tried to use DataTable, but it's not working for me.
Is there a way to do this using DataTable or any other way in C#?
I am trying the evaluate an expression using DataTable, But it's throwing the below exception on line
var temp = dt.Compute(formula, filter);
I have followed this documentation but it didn't help me.Cannot evaluate. Expression 'System.Data.NameNode' is not an aggregate
The expected output is 2 here. I have followed this answer. I am just avoiding using any external library. because I tried to Flee library but it's quite unstable.
So if you pass value 3 in place of 1 to this, then it should return 6.
.net framework version: 4.7.2