在C#中对DataTable进行排序 [英] Sort DataTable in C#

查看:1615
本文介绍了在C#中对DataTable进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我将游标从Oracle返回到DataSet.我想对DataTable中的行进行排序,以便对它们进行排名.但是,该顺序将是"column3"/"column4"的结果.我没有运气就尝试了以下方法.

Hello,
I return a cursor to a DataSet from Oracle. I would like to order the rows in the DataTable so I could rank them. However the order would be be the result of "column3" / "column4". I have tried the following with no luck.

DataTable crsDT = ds.Tables[0].Copy();
DataRow[] rows = new DataRow[crsDT.Rows.Count-1];
rows = crsDT.Select("column4 != 0","column3 / column4");



我知道我可以遍历数据并获得预期的结果,但是我想尝试一些新的方法,看看它是否会更有效.



I know I can loop through the data and get my intended result, but I wanted to try something new to see if it would be more efficient.

Is this possible or should I go a different direction?

推荐答案

您能不能做这样的事情?

Could you not do something like this?

foreach( DataRow row in ds.Tables[0].Select("","column3 / column4") )
{
 int Rank = row.Item("column3") / row.Item("column4");

 // Do something with row and rank?
}


如何将计算列添加到DataTable并使用它?
How about adding a computed column to the DataTable and using that?


这篇关于在C#中对DataTable进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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