Getting source does not contain any data row

I am trying to excute an linq query :

dt2.asenumerable.where(function(row) row (“address”).tostring.contains(addressvar) and row("city).tostring.contains(cityvar) and row (“province”).tostring.contains(provincevar) and row(“zip”).tostring.contains(zipvar)).copytodatatable

dt2 : datatable where i need to check the values
and addressvar ,cityvar,province var and zip var are variables coming through an loop

i am getting the output but with also an error “source does not contain any data row”
How to solve this

It means that the LINQ query didn’t find any matching rows in your dt2 DataTable based on the conditions you specified.

So first use a if condition and then try to use the linq query something like this

revised example of your LINQ query with added checks:

If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 
Then
   Your linq query 
Else
    ' Handle the case where 'dt2' is empty or null.
End If

Hope this helps

Cheers @Pogboom

there were two outputs with same values but one had spaces in it and i want to write only one not duplicate
the error is due to any spacing ? if yes how to handle it

1 Like

You can delete that spaced one present in it

@Pogboom

how to write unique values then in a an excel i am getting duplicates

Can you share the sample data so i can provide the solution

@Pogboom

i am getting data like this :

pratap nagar , nagpur, mh,440022
pratap nagar ,nagpur ,mh,440022

i need to write only value in an excel sheet

1 Like

Use remove duplicates before using condition or linq

https://docs.uipath.com/activities/other/latest/workflow/remove-duplicate-rows

Hope this helps

Cheers @Pogboom

tried using that activity not working

Based on specific column to be removed the duplicates or consider the whole data table
@Pogboom

Fine use a assign activity and mention this expression to remove such duplicates in specific column

dt = dt.AsEnumerable().GroupBy(Function(row) row("your column name").ToString().Replace(" ", "")).Select(Function(group) group.First()).CopyToDataTable()

If it’s for entire table without any specific column

dt = dt.AsEnumerable().GroupBy(Function(row) String.Join("|", row.ItemArray.Select(Function(cell) cell.ToString().Replace(" ", "")))).Select(Function(group) group.First()).CopyToDataTable()

Cheers @Pogboom

whole datatable linq is looking for same data in both sheet then writing it in an new sheet with all the duplicates after that i want to remove the duplicates and proceed with further automation

HI you can try this @Pogboom

it will remove all the duplicates

dt.AsEnumerable().GroupBy(Function(row) String.Join(“|”, row.ItemArray.Select(Function(cell) cell.ToString().Replace(" ", “”)))).Select(Function(group) group.First()).CopyToDataTable()

you can see the input and out put

It has removed the 2nd row
hope its worked

@Pogboom

Let us know if u r facing any challenges with this expression
@Pogboom

i tried using for entire table i am getting this error : activity type "visualbasicvalue’1’ requires compilation in order to run

You can try this

dt.AsEnumerable().GroupBy(Function(row) String.Join("|", row.ItemArray.Select(Function(cell) cell.ToString().Replace(" ", "")))).Select(Function(group) group.First()).CopyToDataTable()

input
image

output : -

image

after pasting this query in your studio you can remove the double quotes and give again then it will work

@Pogboom

still getting the error are the values are in .tostring only