1

I need to convert a DataTable to IEnumerable then use LinqBridge properly... I need to parse a SELECT * FROM X query into a Query.GroupBy(l => l.Field); in order to use some foreach loops correctly grouping my query...

I've tried

public static IEnumerable<DataRow> getRows(DataTable table)
{
    foreach (DataRow row in table.Rows)
    {
        yield return row;
    }
}

But I can't use getRows(myDataTable).Any() or other Linq functions... Some help please.

I can't upgrade from Framework 2, my department wants to downgrade from my 4.0 app to 2.0 because they absoluty deny upgrading the computers, so now I'm very frustrated because my app was WPF 4.0 and I'm migrating everything to WinForm (which is a mess) and updating every method...

Thank you so much.

EDIT

Found the problem, I was calling using LinqBridge but forgot to add after that using System.Linq now the problem is solved and everything working... Delete this post please, or leave it here in order to guide people like me and let them know they need to call System.Linq...

Robert W. Hunter
  • 2,895
  • 7
  • 35
  • 73
  • I didn't think Linq was supported on .NET 2.0? From memory, it first arrived in 3.5... – RB. Mar 27 '13 at 14:20
  • Are you using the 3.5 framework (which is part of the 2.0 runtime)? If you are, you can use the `AsEnumerable()` extension on the DataTable, like [here](http://stackoverflow.com/a/5298438/745969). – Tim Mar 27 '13 at 14:33
  • I am using 2.0 Framework, can't use AsEnumerable(), so this was the only solution. – Robert W. Hunter Mar 27 '13 at 15:53

2 Answers2

2

Try the DataTable.Select method

http://msdn.microsoft.com/en-us/library/system.data.datatable.select(v=vs.80).aspx

Rob
  • 5,578
  • 3
  • 23
  • 28
0

Found the problem, I was calling using LinqBridge but forgot to add after that using System.Linq now the problem is solved and everything working with the method I've posted on my question.

Robert W. Hunter
  • 2,895
  • 7
  • 35
  • 73