datatable.AsEnumerable doesn't work (basic example)

10.2k Views Asked by At
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).

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

edited/added: The following is what I have, where "emptyrows" is a subset array of rows from 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
2

There are 2 best solutions below

3
On

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"

GroupBy:

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

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

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!!