Conversion of string into integer from data table

I’m wondering will that solution throw an error if a value is not a number though?
Typically, you will want to check the value before converting, but am wondering if that way works with no errors.

An alternate, and to me an easier to understand, method would be to filter the table as an enumerable and use the .Where() method.

dt.AsEnumerable.Where(Function(r) If(IsNumeric(r("Ageing").ToString.Trim), Convert.ToInt32(r("Ageing").ToString.Trim) > 7, False).ToArray

Instead of .ToArray you can use .CopyToDataTable, but I will usually use .ToArray when I want to process items in a dataset but keep the entire dataset still there.

In english it basically says, “Go through each row in dt, and if the value is a number, then compare with 7 and select row, if it is not a number then don’t select row… convert to Array to process only the rows that meet the criteria”

Regards. @Ayush_Mishra

4 Likes