Sorting Datatable column with special characters

Hi Guys,

Could you please provide a solution for my issue.

I have a datatable with me in excel sheet with 3 columns and I need to sort it based on column Incomplete.

I tried different approaches like

  1. Assign activity = (From x In statisticsDt .AsEnumerable()Order By convert.ToString(x("Incomplete“))Select x).CopyToDataTable()

  2. dt.DefaultView.Sort = ("[columnname] ASC")
    dt = dt.DefaultView.ToTable


After using above solutions I got like this. which is not correct.


Give a try to sort on numeric value. So you have rewrite the linq and removed the percent sign and Convert the remaining String to e.g. double

If I use below assign then I got output as below (From x In statisticsDt .AsEnumerable()
Order By convert.ToString(x("Incomplete“)) Ascending
Select x).CopyToDataTable()
Sorting is done perfectly but format is not correct for few values.

If I use Descending then I got output as below.

Is there anything I need to do for maintaining the same format for complete column

Give a try on following

(From x In statisticsDt.AsEnumerable()
Order By convert.ToDouble(x(“Incomplete“).toString.replace(”%","").trim) Ascending
Select x).CopyToDataTable()

Kindly Note. Im travelling and do answer from my mobile. So it was Not possible to Check the Syntax. Maybe some corrections are to so. Maybe Convert does Not Like the comma. So do some Experiments in this direction

1 Like

Hi @ ereddy068,

it look like the problem is in your excel and not in your variable, before store the data in that column try to take the column or sheet wherever to Text or number … and run it again …

The problem is not always in what you are doing it can be in what you alredy have.