Hi,
I have 2 DataTables which are vTabExport and vTabOld.
I want to delete the rows of vTabExport which the value of the vTabExport Columnindex 3 is the same as the value in vTabOld Columnindex 1.
I don’t know if there is an explicit activity to do this but, what I have been trying is to get the IndexNumber of the RowExport in order to later delete it.
What I have been trying is:
For each RowExport in vTabExport:
For each RowOld in vTabOld:
if RowExport(3).ToString.Trim=RowOld(1).ToString.Trim
Assing IndexNumber = vTabExport.Rows.IndexOf(RowExport)
With this I get the IndexNumber of the vTabExport Row to be deleted but I don’t know how to delete it.
The assign activity is inside a For Each row Loop activity so, the RowExport cannot be deleted with the “Remove Data Row” activity because the index numbers of the rows are modified so the For Each row Loop cannot proceed.
I have been trying to have a list, an array or something similar to keep adding the IndexNumber’s but I can’t make it work.
Could someone help me please?
Maybe there is an easier way to carry out this process. I would be very glad to hear it.
PD: I have also tried the Add To Collection Activity but there is some error(s) regarding the type of Collection variable (Array or List).
Try linq Given Below :
replace col2 with your Column name
It will give you ypur excepted Output
Your_dt1.AsEnumerable().Where(Function(y) Not Your_dt2.AsEnumerable().Select(Function(x) x(“col2”).ToString().Trim()).Contains(y(“col2”).ToString().Trim())).CopyToDataTable()
Sorry for the confusion. I will clarify with an example:
Input: 2 DataTables
vTabExport:
Columna 1
Columna 2
Columna 3
Columna 4
A
B
C
D
vTabOld:
Columna 1
Columna 2
Z
T
A
V
C
The purpose is to delete the entire rows of the vTabExport Table (RowExport) on which the content of its columnindex 3: RowExport(3) is the same as the content of a Row of the vTabOld Table (RowOld) columnindex 1: RowOld(1)
So the condition which states which rows of vTabExport must be deleted is:
if RowExport(3).ToString.Trim=RowOld(1).ToString.Trim
In this example this occurs with the letters A and C.
This way, the expected output is to have the vTabExport table as the following one: