Delete data row from data table

Hi there @1vivek12,
You can do the following:

Assign – dtMyDataTable = dtMyDataTable.AsEnumerable.GroupBy(Function (x) x.Item("Sector_ID")).Select(Function (i) i.First).CopyToDataTable

This will return the first rows with unique values in the column “Sector_ID”.

Thanks,
Josh

2 Likes

Dear @aksh1yadav and @Mr_JDavey
I want to delete the row where Variable match is found
tried below following by for each loop and Remove Activity, if I pass value manually it is working fine but not working with variable, please help

image

There is no need to loop and delete.i think below should do the same.give a try.

Data = Data.Select(“[Status] <> '”+Policy_num+“'”).CopyToDataTable

3 Likes

@vvaidya I thing above code is just to select , How to delete selected row

Attaching the XMAL with Sample data

Delete Processed Policy.zip (24.4 KB)

Hey @Aditipatil

It will just create a new datatable with results where no match will be there. so you can use that datatable for your further operation.
if you wanna delete rows then there is post already exist by me, so search it :slight_smile:

REgards…!!
AKsh

Hi @aksh1yadav , yes I had followed the post from you on 26 Oct above in this trail.

It has given the required result but if output file name is change , I need the result in same file as it has to be used for rest of policies, please check below and guide

Delete Processed Policy aksh.zip (22.2 KB)

1 Like

Hey @Aditipatil

Yes you can overwrite the results in the same excel.

just use Write Range ACtivitiy with blank range on the same excel file.

Regards…!!
Aksh

Hi @aksh1yadav thanks for response , tried below but result is same, for detail I had attached XMAL in previous post

image

Excel Application scope try. it :slight_smile:.

worked out but it is filling the stake with the last item

image

Great :slight_smile:

Their is problem with your assignment or something… check your datatable content first before writing with output datatable activity in studio: :slight_smile:

Regards…!!
AKsh

Hi I would need to delete all odd numbers from table I just created. Can I use the .Select -method? And how?

Will you be able to explain a bit more with description or expected input or output

Thanks


Yeas, so at the moment this is what I have. The Output looks something like:
7
3
6
4
10
5
etc…

But I would like to delete all odd numbers. In this case the ouytput would be like:
6
4
10
2
etc… (So only even numbers)

hey @naample

please find attached sample :slight_smile: sample for even values of a col.xaml (11.6 KB)

Regards…!!
Aksh

1 Like

Thank you so much :slight_smile:

@aksh1yadav … Please can you suggest something for below scenario.
I have data in two data tables DT1 and DT2 . I want to delete data from DT1 if dt1.empid = dt2.contractorid .

I have taken two for loop and in inner for loop I have if condition with this check(dt1.empid = dt2.contractorid).
but its not workign, throwing exception.

Hi @narayan_shrawagi,

Datatable->Dt1
Datatable->D2
User for each row activity ->Dt2

use Assign activity
Dt1=Dt1.Select("empid <> '"+row("contractorid ").Tostring()+"'").CopyToDataTable()

Regards,
Arivu

hey @narayan_shrawagi

If you will read all post in this thread above you can get your approach and idea.

you can instead of delete much rows take only those data which is needful for next step so just check your idea from above existing post and get the actual context and if still face any prob let me know.

Solution Without Usign for each:

Datatable result = DT1.AsEnumerable().Where(function(row) Not DT2.AsEnumerable().Select(function(r) r.Field(Of Int32)("Contractorid")).Any(function(x) x = row.Field(Of Int32)("empid"))).CopyToDataTable()

Sample To check: - datatable column match.xaml (10.7 KB)

REgards…!!
Aksh

3 Likes

try while loop instead of for loop if you want to use Remove Datarow