confusedMind
confusedMind

Reputation: 2653

Issue sorting DataTable c#

Supposing i have the following values in a column in DataTable

120,00
200,00
201,00
12510,00

On sorting them in ASC ORDER i am always getting the 12510,00 on top and remaining sort perfectly fine. Any suggestion?

Upvotes: 1

Views: 87

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460108

I assume it's a string column, you should fill it with the correct type. If that's not possible you can use decimal.Parse, for example:

tbl = tbl.AsEnumerable()
    .OrderBy(row => decimal.Parse(row.Field<string>("ColumnName")))
    .CopyToDataTable();

You need to add using System.Linq.

If you use a different decimal separator you can use decimal.Parse(row.Field<string>("ColumnName"), new CultureInfo("de-DE")).

Upvotes: 2

Related Questions