views:

82

answers:

1

I need to group a data table on multiple columns and also read data of un-grouped columns

col1 col2 col3 col4 col5 col6 col7 col8 .. col16

Here i am grouping it on col1, col2 ... col6. But facing problems in reading values of col7 ... col16

var groupedRows = from myTable in table.AsEnumerable()
                  group myTable by new
                  {
                      Col1 = myTable["Col1"],
                      Col2 = myTable["Col2"],
                      Col3 = myTable["Col3"],
                      Col4 = myTable["Col4"],
                      Col5 = myTable["Col5"],
                      Col6 = myTable["Col6"]
                  }
                  into groupedTable
                  select new
                  {
                      x = groupedTable.Key,
                      y = groupedTable
                  };

Code where i am facing problem is

foreach (var row in groupedRows)
{
    record = new Record();
    record.col1 = row.x.col1.ToString();
    record.col2 = row.x.col2.ToString();
    record.col3 = row.x.col3.ToString();
    record.col4 = row.x.col4.ToString();
    record.col5 = row.x.col5.ToString();
    record.col6 = row.x.col6.ToString();

    var groupdata = groupedRows.Select(x => x.y);
    if (groupdata.Count() > 0)
    {
        var groupdatas = groupdata.First();
        foreach (var item in groupdatas)
        {
        }
    }
}

I am trying to read var groupdata = groupedRows.Select(x => x.y); data of ungrouped columns but no use.

I am facing problem in reading data from y. Can anyone please suggest me on how to read?

A: 

After this, you'll end up with a list of lists: i.e. a list of groups, each with a list of rows belonging to that group. Your groupedTable variable will be a list of the rows within that group.

It depends what you're trying to assign to y really, but if you understand that, hopefully you'll be on the right track.

Tim