Problem with data table which mod's odd numbers out

I got an data table with numbers and I want to filter out all odd numbers from it and print out the even numbers. I got an idea what to do, I create the datatable from array of int32 or from string(which 1 is better choice?) and then build the data table from those, but I ran into conversion issues when I try use the “number mod 2 = 0” case. Is filter wizard an possibility to use?
intstringproblem.xaml (9.0 KB)

Hi,

Can you try the following?

dt=dt.AsEnumerable.Where(function(r) CInt(r("Value")) Mod 2 =0).CopyToDataTable

Regards,

Hey I get conversion from string to type integer is not valid error.

And I can’t edit type of string into data table type of integer when embryo is integer.

Hi,

Probably your data contains non-numeric character or empty.
Can you try the following?

dt=dt.AsEnumerable.Where(function(r) IsNumeric(r("Value")) AndAlso CInt(r("Value")) Mod 2 =0).CopyToDataTable

Regards,

Yeah I got given input as string input “1 2 3 4 5 6 7 8 9 10” and that’s what I was questioning should I have it as int array instead?

Hi,

I suggested above expression because your title of this post is about DataTable.
If you want to filiter just ths string, I’ll suggest the follwing.

str_ten=Split(givenInput," ")
str_ten=str_ten.Where(function(x) CInt(x) Mod 2 =0).ToArray

You’ll be able to get filtered array of string.

Regards,