Remove odd numbers of Data table and show the new Data table with only even numbers

Hi everyone! I have a data table from 1-10, how can I remove odd numbers and show the newData table with even numbers only

@Duong,

Its Easy, As simple as below

if(num%2 == 0){
“Number is even”
}else{
“Number is odd”
}

Please mark this as resolved if your requirement met.

Thanks,
Anil

Hi @Duong,

Welcome to our Community!.

Check this attached xaml,

FilterData.xaml (4.9 KB)

Also check this post for more details

1 Like

@Duong
As an alternate give a try on:
yourDataTableVar.AsEnumerable.Where( function ( row ) CInt(row(“yourColumnName”).toString) Mod 2 = 0).CopyToDataTable

same as @sarathi125 he answered faster and i didn’t noticed :slight_smile:

1 Like

Thank you! I have tried but there is error: ColumnName doesn’t belong to Datatable eventhough I set it in Build Datatable. How could I fix it?

You should mention correct column name which you had in the Build DataTable activity.


Can you check? I did it but the error is still there

In the assign you can assign the filtered to the DT1 itself, else you need to have one more Assign Activity with DT2 = DT1.Clone this will create the columns in DT2.

Currently no Columns defined or created in DT2. Thats the problem.

Thank you, column name error is fixed. There is other error conversion into int doesn’t work in this case. The input is int. How can I modify it?

@Duong
please provide us details on error (e.g. message). maybe give also some sample values on what you are using for conversion

The error as follows:
Source: Assign

Message: Conversion from string “” to type ‘Integer’ is not valid.

Exception Type: System.InvalidCastException

RemoteException wrapping System.InvalidCastException: Conversion from string “” to type ‘Integer’ is not valid. —> RemoteException wrapping System.FormatException: Input string was not in a correct format.

The data table print out like this:
Numbers
2
4
5
7
10
1
3
6
9
8

@Duong
can you share your xaml?

I cannot unfortunately. New user…
From an array of Int I built a data table and added rows.

Now I have to remove odd numbers from the data table and show data table with even numbers only. Later I have to sort the data table ASC later.

ok give me some little time, keep in mind you could do it also directly on the Array

1 Like

@Duong
have a look on doing that on the array directly
Duong.xaml (6.4 KB)

feel free to play with it or to integrate in your workflow

It works!! Thank you very much!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.