How to keep only numeric values in a single colomns datatable DT?

How to keep only numeric values in a single colomns datatable DT ?

i used “double.TryParse(row[“NomDeLaColonne”].ToString().Trim().Replace(‘,’, ‘.’), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out dummy)”

but there is compilation errors

@abdel,

Use this code in Invoke code:

For Each row As DataRow In dtInput.Rows
Dim dummy As Double = 0
Dim valueStr As String = row(“NomDeLaColonne”).ToString().Trim().Replace(“,”, “.”)

If Double.TryParse(valueStr, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, dummy) Then
    ' Successfully parsed, update the value if needed
    row("NomDeLaColonne") = dummy.ToString()
Else
    ' Parsing failed; you can either clear the column cell or leave it unchanged
    row("NomDeLaColonne") = String.Empty
End If

For Each Row in Datatable

  • If NOT IsNumeric(CurrentRow(“column name”).ToString)
    • Assign CurrentRow(“column name”) = newvalue

Hi @abdel

Try below expression,

DT = DT.AsEnumerable().Where(Function(row) IsNumeric(row("ColumnName").ToString())).CopyToDataTable()

Regards,
Gowtham K

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