Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have used to select method to get the data from datatable.
For example,
DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("Group", typeof(int)));
        dt.Columns.Add(new DataColumn("name", typeof(string)));
        DataRow dr = dt.NewRow();
        dr["Group"] = 1;
        dr["name"] = "Apple";
        dt.Rows.Add(dr);
        dr["Group"] = 2;
        dr["name"] = "Milk";
        dt.Rows.Add(dr);
        dr["Group"] = 1;
        dr["name"] = "Orange";
        dt.Rows.Add(dr);
        dr["Group"] = 2;
        dr["name"] = "Curd";
        dt.Rows.Add(dr);

So the following order the data is in datatable
Group Name
=================
1 Apple
2 Milk
1 Orange
2 Curd

The following select statement to get the data.
DataRow[] dr1 = dt.Select("group in (1,2)");

But the items are fetching different order. like this
Group Name
====================
1 Apple
1 Orange
2 Milk
2 Curd

I need to fetching the actual order. Like this

Group Name
====================
1 Apple
2 Milk
1 Orange
2 Curd

How to get above order for using select statement in asp.net?

Thanks in Advance
Posted
Updated 30-Aug-10 21:45pm
v2

You use an order by clause to specific the order of your data. It seems to be ordering by group by default, so you need to be able to specify the order by some value.
 
Share this answer
 
Hi All,

I tried to use dataview rowfilter instead of datatable.select when it is working fine.
Here this,
DataView dv = dt.DefaultView;
dv.RowFilter = "group in (1,2)";
dt = dv.ToTable();


I got solution.

Thanks
 
Share this answer
 
v2
SQL
can we use "dt.Select("group <b>not</b> in (1,2)")"?????
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900