1
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
user3496060
  • 800
  • 10
  • 20

2 Answers2

5

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"))
OneFineDay
  • 9,004
  • 3
  • 26
  • 37
  • Thanks - but the reason I asked about the form above is because I want to use "new with" to group by multiple column values, but only after applying a "where row("column name") = "something"" clause to get a subset from the table. I can do this by doing a "datatable.select" search and then a linq query, but wanted to do it all in a linq query. – user3496060 Jun 28 '14 at 17:29
  • 1
    I don't feel I understand what your asking for exactly. – OneFineDay Jun 28 '14 at 17:32
  • I added/edited my question above. I should have just put the full question up in the first place. My apologies. – user3496060 Jun 28 '14 at 18:08
-1

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

user3496060
  • 800
  • 10
  • 20