title: GroupBy and Sum on a DataTable
body: <p>I am using LINQ in VB on a datatable to filter my results.</p>
  
  <pre><code>m_oDataTable.Columns.Add("Name1", GetType(String))
  m_oDataTable.Columns.Add("Name2", GetType(String))
  m_oDataTable.Columns.Add("Time", GetType(Double))
  </code></pre>
  
  <p>I am trying to filter the datatable by <code>Name1</code> or <code>Name2</code> based on user selection.</p>
  
  <pre><code>groupBy = "Name1" 
  'groupBy = "Name2"
  </code></pre>
  
  <p>I grouped my data but I was unable to <code>Sum</code> the desired field.</p>
  
  <pre><code>Dim test =  From tab In m_oDataTable.AsEnumerable()
              Group tab By groupDt = tab.Field(Of String)(groupBy) Into Group
              Select Group
  
  'Getting Error
  Dim test2 = From tab In m_oDataTable.AsEnumerable()
              Group tab By groupDt = tab.Field(Of String)(groupBy) Into Group
              Select New With 
              {
               .Grp = Key, ' Error in this line(Key is a type, cannot be used as a expression)
               .Sum = Group.Sum(Function(r) Double.Parse(r.Item("Time").ToString()))
              }
  </code></pre>
  
  <p>I tried in c# and got the desired result. But have no luck with VB :(</p>
  
  <pre><code>var test = from tab in m_oDataTable.AsEnumerable()
             group tab by tab.Field&lt;string&gt;(groupBy)
                   into groupDt
                   select new
                   {
                       Group = groupDt.Key,
                       Sum = groupDt.Sum(r =&gt; double.Parse(r["Time"].ToString()))
                   };
  </code></pre>
  
  <p>How to achieve this in VB?</p>