数据表选择和排序 [英] Datatable Select and Sort

查看:111
本文介绍了数据表选择和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我曾经使用过select方法来从数据表中获取数据.
例如

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);


因此,以下顺序的数据在datatable中
组名
=================
1个苹果
2牛奶
1橙
2凝乳

下面的select语句获取数据.


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)");


但是这些物品正在获取不同的订单.像这样
组名
===================
1个苹果
1橙
2牛奶
2凝乳

我需要获取实际订单.像这样

组名
===================
1个苹果
2牛奶
1橙
2凝乳

如何在asp.net中使用select语句获得高于顺序的结果?

在此先感谢


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

推荐答案

您可以使用order by子句来指定数据的顺序.似乎默认情况下按组排序,因此您需要能够按某个值指定顺序.
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.


大家好,

当它工作正常时,我尝试使用dataview rowfilter而不是datatable.select.
在这里,
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


can we use "dt.Select("group <b>not</b> in (1,2)")"?????


这篇关于数据表选择和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆