vb.net datatable.AsEnumerable 不起作用(基本示例)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24468808/
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-17 17:47:54  来源:igfitidea点击:

datatable.AsEnumerable doesn't work (basic example)

vb.netlinqasenumerable

提问by user3496060

Dim x = From row In f_table.AsEnumerable()
                    Select row("Crop")

From what I understand, the "f_table.AsEnumerable" should make my search object ("row" in this case) a datarow object. This simple example runs without any exceptions but does not find any entries (This search works if I switch to an array of datarows that have been taken from f_table, in place of f_table.AsEnumerable).

据我了解,“f_table.AsEnumerable”应该使我的搜索对象(在本例中为“row”)成为数据行对象。这个简单的示例运行时没有任何异常,但没有找到任何条目(如果我切换到从 f_table 获取的数据行数组,而不是 f_table.AsEnumerable,则此搜索有效)。

Any ideas why AsEnumerable is not allowing for searching the rows of the table?

为什么 AsEnumerable 不允许搜索表的行的任何想法?

edited/added: The following is what I have, where "emptyrows" is a subset array of rows from f_table.

编辑/添加:以下是我所拥有的,其中“emptyrows”是 f_table 中行的子集数组。

Dim emptyrows_grouped = From row In emptyrows
                                Order By row("Date"), row("Time")
                                Group By New With {.date = row("Date")}.date,
                                         New With {.crop = row("Crop")}.crop
                                Into Group

What i want is this form:

我想要的是这种形式:

Dim emptyrows_grouped = From row In f_table.AsEnumerable
                                Where row.Field(Of String)("SamplePosition") Like "Emp%"
                                Order By row("Date"), row("Time")
                                Group By New With {.date = row("Date")}.date,
                                         New With {.crop = row("Crop")}.crop
                                Into Group

回答by OneFineDay

It works like this:

它是这样工作的:

 Dim query = dt.AsEnumerable
             .Where(Function(dr) dr("column name").ToString = "something").ToList

This yields a List of DataRows where this column has the value of "something"

这会产生一个 DataRows 列表,其中该列的值为“某物”

GroupBy:

通过...分组:

 Dim query = dt.AsEnumerable
             .Where(Function(dr) dr("column name").ToString = "something")
             .GroupBy(Function(dr) dr("column name"))

回答by user3496060

Never mind - I'm a gigantic fool today because f_table is the wrong datatable. I used the right one and it worked.

没关系 - 今天我是个大傻瓜,因为 f_table 是错误的数据表。我使用了正确的方法,并且奏效了。

Dim emptyrows_grouped = From row In file_table.AsEnumerable
                                Where row.Field(Of String)("SamplePosition") ="Empty"
                                Order By row("Date"), row("Time")
                                Group By New With {.date = row("Date")}.date,
                                         New With {.crop = row("Crop")}.crop
                                Into Group

Please excuse my wasting of your time!!

请原谅我浪费你的时间!!