I would like to use LINQ on DataTable by Invoking CODE, here below my statement:
i_dt input DataTable argument
o_dt output DataTable argument
var results = from myRow in i_dt.AsEnumerable()
where myRow.Field(“Amount”) > 1000
o_dt = results.CopyToDataTable();
this stage raise the following error: Private: Invoke code: Exception has been thrown by the target of an invocation.
What’s strange to me:
- inside Invoke code activity you do not have debug, you do not see i_dt, o_dt values
- comment out //o_dt = results.CopyToDataTable(); the error does not appear.
- so just tried to modify “Amount” in fake “Amount_sic” and code runs without error.
So i cannot catch up whats wrong with it. Is there a way to troubleshoot it?
Which error do you have?
We can know it from $ExceptionDetails at LocalsPanel when workflow stops in Debug.
If you have
The source contains no DataRows. , your datatable doesn’t have rows match your condition. Perhaps you should check count of the rows before using CopyToDataTable method.
we can do this within an assign activity, doing a check on int base and can handle defensive the empty filterresult as mentionend by @Yoichi
LHS: Result | DataType: List(Of DataRow) =
(from myRow in dtData.AsEnumerable()
where CInt(myRow("Amount").toString.Trim) > 1000
select r = myRow).toList
then check within an if acitvity
Result.Count > 0
Then: dtResult = Result.CopyToDataTable
Else: dtResult = dtData.Clone
In case of Int conversion issues we can add some handlings on non parseable Amount values as well
Hello, seems like it does not like the expression (see picture attached
)… translated it said “overload not accepted … fields cannot call with those arguments” … “impossible to know parameter of type T” …
the syntax is used wrongly within the statement from your screenshot.
check first if provided LINQ will work. After this access with the field method can be checked.
sorry don’t catch you what you mean if provided LINQ will work and how can I check it out …
much better … thank you
after that the feedback is List(Of DataRow) cannot be converted in List(Of String) … so just switched Result in List(Of DataRow) and no more errors apart this below when encounter dot notation … so converted in Double but still get error … is it something about Culture to set up before ?
Assign: Conversion from string “16.355,25” to type ‘Double’ is not valid.
feel free to use any other culture matching your location, but defining the format as reflected from the data
ensure System.Globalization is added to the imports
(From myRow In dtData.AsEnumerable() Where (Double.Parse(myRow(“Amount”).toString.Trim), New CultureInfo(“de-DE”) ) > 1000 Select r = myRow).toList
get back sintax error ‘)’ missing … sorry
its about brackets
(From myRow In dtData.AsEnumerable()
Where Double.Parse(myRow(“Amount”).toString.Trim, New CultureInfo(“de-DE”) ) > 1000
Select r = myRow).toList
removed: before Double, after trim for example.
In case of bracket issues just count with finger up / down when its opening and closing. If not all fingers are down, then identify and correct the brackets. For sure also respect method signatures when counting the brackets
stupid me works great, Thansk!
Again, do you know where can I found any LINQ reference in VB scope (even if c@ preferreble) ?
e.g. I do not understand the following statement … Select r = myRow).toList … “r” where it come from ?
r is like a local variable used within the LINQ
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.