title: Group a Datatable and copy to another table C#
body: <p>There is already a question here "<a href="https://stackoverflow.com/questions/27121248/report-generation-in-asp-net">https://stackoverflow.com/questions/27121248/report-generation-in-asp-net</a>". I have same scenario where i have stocked on a specific point. </p>
  
  <p>Please Help.</p>
  
  <p>My DataTable has three columns </p>
  
  <pre><code>Name  Plot   Area
  a     12     .90
  a     13     .30
  b     12     .45
  b     13     .46
  c     13     .98
  </code></pre>
  
  <p>I want my result to be </p>
  
  <pre><code>Name  Plot  Area
  a     12    .90
        13    .30
  b     12    .45
        13    .46
  c     13    .98
  </code></pre>
  
  <p>And this is what i have tried . I have grouped this to linq and need to copy to another table. How can i achieve this :</p>
  
  <pre><code>static class Program
  {
      static void Main(string[] args)
      {
          try
          {
  
              DataTable dtMain = new DataTable();
              dtMain.Columns.Add("Name", typeof(string));
              dtMain.Columns.Add("Plot", typeof(int));
              dtMain.Columns.Add("Area", typeof(decimal));
  
              DataRow dr1 = dtMain.NewRow();
              dr1["Name"] = "a";
              dr1["Plot"] = 12;
              dr1["Area"] = .90;
              dtMain.Rows.Add(dr1);
  
              DataRow dr2 = dtMain.NewRow();
              dr2["Name"] = "a";
              dr2["Plot"] = 13;
              dr2["Area"] = .30;
              dtMain.Rows.Add(dr2);
  
              DataRow dr3 = dtMain.NewRow();
              dr3["Name"] = "b";
              dr3["Plot"] = 12;
              dr3["Area"] = .45;
              dtMain.Rows.Add(dr3);
              DataRow dr4 = dtMain.NewRow();
              dr4["Name"] = "b";
              dr4["Plot"] = 13;
              dr4["Area"] = .46;
              dtMain.Rows.Add(dr4);
              DataRow dr5 = dtMain.NewRow();
              dr5["Name"] = "c";
              dr5["Plot"] = 13;
              dr5["Area"] = .98;
              dtMain.Rows.Add(dr5);
  
              DataTable dtFinal = dtMain.Clone();
  
              var groupedData = (from b in dtMain.AsEnumerable()
                                 group b by b.Field&lt;string&gt;("Name") into g
                                 select new
                                {
                                    Name = g.Key,
                                    Plot = g.Select(x =&gt; x.Field&lt;int&gt;("Plot")),
                                    Area = g.Select(x =&gt; x.Field&lt;Decimal&gt;("Area")),
                                }).ToList();
  
        //Next what should i do here.CopyToDataTable() no longer getting the correct data.
         dtFinal = groupedData.ToList().CopyToDataTable();
  
              Console.ReadLine();
          }
          catch (Exception objEx)
          {
              Console.WriteLine(objEx);
          }
      }
  
  
  }
  </code></pre>