Hi All,
i have excel sheet and i need to filter a column. it contains numeric values and string values.
I need to filter and get the rows which are grater than 18 if their age.
this code is working when column contains numeric values.
Sometimes i get only string values at the time i’m getting error with that. How can i handle that exception . any help in code modification.
(From d in dtData.AsEnumerable
Let ag = d("Age")
Where Not (isNothing(ag) OrElse String.IsNullOrEmpty(ag.toString.Trim) )
Where Double.TryParse(ag.ToString.Trim, nothing)
Where Double.Parse(ag.ToString.Trim) > 18
Select r = d).CopyToDataTable
@ppr if the input comes likes this then it is throwing error. If it contains at least 1 numeric value it won’t throw error. I will check that link what you have sent.
(From d in dtData.AsEnumerable
Let ag = d("Age")
Where Not (isNothing(ag) OrElse String.IsNullOrEmpty(ag.toString.Trim) )
Where Double.TryParse(ag.ToString.Trim, nothing)
Where Double.Parse(ag.ToString.Trim) > 18
Select r = d).ToList
then model the if and check if there are Datarows returned or not
DT.AsEnumerable().Where(Function(row)
Dim ageString As String = row.Field(Of Object)(“Age”).ToString()
Dim isNumeric As Boolean = Double.TryParse(ageString, 0)
If isNumeric Then
Dim ageValue As Double = CDbl(ageString)
Return ageValue > 18
Else
Return False
End If
).CopyToDataTable()
Whenever an error is encountered, the detail information is also to share directly. We avoid ping-pong communication and the support can be done more efficently.
Reread the FirstAid and follow the described steps