2010-07-29 35 views
0

我需要从DataTable中检索一组“Top n”行数,其中表行按Ordered By“Column X”排序,但只有当行的“列X”值大于提供的比较值。这是我到目前为止有:如何比较LINQ查询中的字符串列值?

EnumerableRowCollection query = from history in dt.AsEnumerable() 
           where history.Field<string>("Column X") > "Value-To-Compare") 
           orderby history.Field("Column X") 
           select history; 

但我一直收到“操作员‘>’不能被应用到类型‘串’和‘串’的操作数”

有什么想法?

fuzzlog

回答

0

这项工作?

EnumerableRowCollection query = from history in dt.AsEnumerable() 
           where String.Compare(history.Field<string>("Column X"), "Value-To-Compare") > 0 
           orderby history.Field("Column X") 
           select history; 
0

伊恩,做了诡计,谢谢。

对不起,在您给出解决方案后回答我的问题,但我需要增强您的答案,使其与原始请求的100%相匹配。

...检索一组的 “TOP N” 的 行数...

完整的答案应该是这样的:

EnumerableRowCollection query = (
            from history in dt.AsEnumerable() 
            where String.Compare(history.Field<string>("Column X"), "Value-To-Compare") > 0 
            orderby history.Field("Column X") 
            select history 
           ).Take(n); 

其中 “N” 是“Top n”中指定的行数

再次感谢,

fuzzlog