Pogboom
September 25, 2023, 10:23am
1
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
Pogboom
September 25, 2023, 10:28am
4
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
Pogboom
September 25, 2023, 10:41am
6
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
Pogboom
September 25, 2023, 10:46am
8
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
Pogboom
September 25, 2023, 11:10am
10
tried using that activity not working
Based on specific column to be removed the duplicates or consider the whole data table
@Pogboom
Pogboom:
pratap nagar , nagpur, mh,440022
pratap nagar ,nagpur ,mh,440022
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
Pogboom
September 25, 2023, 11:15am
13
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
Palaniyappan:
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()
Let us know if u r facing any challenges with this expression
@Pogboom
Pogboom
September 25, 2023, 11:28am
17
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
output : -
after pasting this query in your studio you can remove the double quotes and give again then it will work
@Pogboom
Pogboom
September 25, 2023, 1:46pm
20
still getting the error are the values are in .tostring only