datatable.AsEnumerable doesn't work (basic example)

user3496060 picture user3496060 · Jun 28, 2014 · Viewed 7.8k times · Source
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

Answer

OneFineDay picture OneFineDay · Jun 28, 2014

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"))