A piece of datatable code I've written which worked before seems to randomly now be failing

Hey there,

I wrote a piece of code which reads an excel spreadsheet and filters a datatable to check a value after removing spaces from it (the purpose of which is due to potential double spacing).

The code is below and has always worked, but suddenly I am getting an error. I’ve even checked the data to ensure what I need is there (it is) and have ran old instances which I know for certain worked before, but no longer do:

oLatestReportDT.AsEnumerable().Where(Function(r) r(“CAP CODE”).ToString.Replace(" “,”“)= iCapCode.ToString.Replace(” “,”") AND CDbl(r(“Basic List Price”).ToString) = iListPrice).CopyToDataTable

The error:

Any help would be appreciated please, this is driving me crazy. Something must have changed somewhere.

Hi @dr1992

Could you share your variable panel, I just want to know the datatypes of variables.

oLatestReportDT is datatable
iCapCode is string
iListPrice is double

Hi @dr1992,

It looks like a boolean is being returned, due to the “AND” in between the operations.
If possible, could you send a sample input file?

Thanks.

Hey, I’m unable to as this contains sensitive information.

If you were to replicate a spreadsheet with the headers of CAP CODE and Basic List Price and gave them fields with ‘qwe rty’ and ‘12345’ then the scenario would be the same.

@dr1992,

Would the below be an appropriate input?

With
iCapCode = “ABC123”
iListPrice = 20.0

Precisely, though the numbers are in the thousands (though I doubt it matters).

@dr1992
I ran it with the exact same LINQ query you had given,

oLatestReportDT.AsEnumerable().Where(Function(r) r("CAP CODE").ToString.Replace(" ","")= iCapCode.ToString.Replace(" ","") AND CDbl(r("Basic List Price").ToString) = iListPrice).CopyToDataTable

And with the below input


iCapCode = “ABC123”
iListPrice = 20000.5

And this worked fine for me:
image

Could you try dragging a new Assign activity with the same fields as in your process and check if the issue persists? :thinking:

This is expected as it was working for me before!

I retried the assign but no luck… this seems like a glitch.

Hi @dr1992

This might happen if there are null values
Can you try this Linq

dt_result =oLatestReportDT.AsEnumerable().Where(Function(r) r("CAP CODE").ToString().Replace(" ", "") = iCapCode.ToString().Replace(" ", "") AndAlso Double.TryParse(r("Basic List Price").ToString(), Nothing) AndAlso CDbl(r("Basic List Price").ToString()) = iListPrice).CopyToDataTable()

Hope this helps

Thank you, though there aren’t null values here…