Why DataTable.Select sorts data by default

I have a dataset with the following data

Name          Value    Percent
0-3 months    0        0
3-12 months   0        0
1-5 years     1234.12  28
5-10 years    13144.11 68
10-15 years   0        0
Over 15 years 1233.44  14
Other Income  2245.12  

when i try

foreach (DataRow dr in dsMaturity.Tables[0].Select("name not like 'Other%'"))
{
    TotalValue += double.Parse(dr["Value"].ToString());
}

Edit: Actually, similar to the code above. I use a similar loop to add data to display the bucket, which is eventually written to the chart.

foreach (DataRow dr in dsMaturity.Tables[0].Rows)
{
    //Add to the display bucket
}

I get data sorted as:

0-3 months
10-15 years
1-5 years
3-12 months
5-10 years
Over 15 years

Why? How can I disable data? This is very important, as I display the data in my chart object. Did I miss something?

+5
source share
7 answers
+2

, / , , :

foreach (DataRow dr in dsMaturity.Tables[0].Rows)
{
    if (!dr["Name"].ToString().StartsWith("Other "))
    {
        // adding it to display bucket
    }
}
+1

, :

dataTable.AsEnumerable();

dataTable.Select();
+1

:

foreach (DataRow dr in dsMaturity.Tables[0].Select("name not like 'Other%'", "column_to_sort_by"))
{
    TotalValue += double.Parse(dr["Value"].ToString());
}

column_to_sort_by - , .

0

?

, , , .

0

If the data is already sorted in the database, it may be sorted for some reason. The data you submitted is sorted by name. Is it like a database?

0
source

Agreed! This is very annoying ... I have the same problem.

If you have .net 3.5+, you can use Linqto filter strings:

var rows = dt.Rows.Cast<DataRow>().Where(r => !((string)r["Name"]).StartsWith("Other")
0
source

All Articles