I have a DataTable containing data like following: (Assume that each line is each datarow) and each space in each line is the column divider.
PackageA
103 104 141 143
201 203 251 249
311 315 388 390
415 416 417 419
PackageB
103 104 141 143
201 203 251 249
311 315 388 390
PackageC
103 104 141 143
201 203 251 249
311 315 388 390
and so on…
Now there is another Excel file that has the corresponding package codes. It looks like
PackageName | PackageCode
PackageA | SN11414
PackageC | SN13315
PackageD | SN41513
Now comes what I want to do. I need to delete from the datatable, any rows that don’t have the corresponding PackageCode. In the above example, since PackageB doesn’t exist in the Excel file, any rows related to PackageB need to be deleted from the datatable. So the resulting datatable has to look like
PackageA
103 104 141 143
201 203 251 249
311 315 388 390
415 416 417 419
PackageC
103 104 141 143
201 203 251 249
311 315 388 390
and so on…
How could I do this? I read that deleting rows should be done in the reverse order so that deleted rows won’t mess up the later indices, but I can’t go in the reverse order this time because the package name comes at the top of each package section.
Also, we don’t know how many rows there are in each package set.