.net 数据表选择方法 ORDER BY 子句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1274976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 13:09:17  来源:igfitidea点击:

Datatable select method ORDER BY clause

.netselectdatatablemethodssql-order-by

提问by jsp

HI, I 'm trying to sort the rows in my datatable using select method. I know that i can say

嗨,我正在尝试使用 select 方法对数据表中的行进行排序。我知道我可以说

datatable.select("col1='test'")

which in effect is a where clause and will return n rows that satisfy the condition.

这实际上是一个 where 子句,将返回满足条件的 n 行。

I was wondering can i do the following

我想知道我可以做以下事情吗

datatable.select("ORDER BY col1")---col1 is the name of hte column

datatable.select("ORDER BY col1")---col1 是 hte 列的名称

I tried datatable.defaultview.sort()but didnt work

我试过datatable.defaultview.sort()但没有用

Any ideas on how to get around this issue. thanks

关于如何解决这个问题的任何想法。谢谢

回答by Forgotten Semicolon

回答by Steve Johnson

Use

datatable.select("col1='test'","col1 ASC")

Then before binding your data to the grid or repeater etc, use this

然后在将您的数据绑定到网格或转发器等之前,使用它

datatable.defaultview.sort()

That will solve your problem.

那将解决您的问题。

回答by Bala Subramaniam

You can use the below simple method of sorting:

您可以使用以下简单的排序方法:

datatable.DefaultView.Sort = "Col2 ASC,Col3 ASC,Col4 ASC";

By the above method, you will be able to sort N number of columns.

通过上述方法,您将能够对 N 列进行排序。