ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Group By multiple Columns in DataTable using LINQ in C# and VB.Net<p>Check the below example.</p> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[3] { new DataColumn(&#34;Id&#34;, typeof(int)), new DataColumn(&#34;Name&#34;, typeof(string)), new DataColumn(&#34;Country&#34;,typeof(string)) }); dt.Rows.Add(1, &#34;John Hammond&#34;, &#34;United States&#34;); dt.Rows.Add(2, &#34;Mudassar Khan&#34;, &#34;India&#34;); dt.Rows.Add(3, &#34;Suzanne Mathews&#34;, &#34;France&#34;); dt.Rows.Add(4, &#34;Robert Schidner&#34;, &#34;Russia&#34;); var result = from rows in dt.AsEnumerable() group rows by new { Name = rows[&#34;Name&#34;], Country = rows[&#34;Country&#34;] } into grp select grp; List&lt;DataTable&gt; dts = new List&lt;DataTable&gt;(); foreach (var item in result) { dts.Add(item.CopyToDataTable()); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn(2) { New DataColumn(&#34;Id&#34;, GetType(Integer)), New DataColumn(&#34;Name&#34;, GetType(String)), New DataColumn(&#34;Country&#34;, GetType(String))}) dt.Rows.Add(1, &#34;John Hammond&#34;, &#34;United States&#34;) dt.Rows.Add(2, &#34;Mudassar Khan&#34;, &#34;India&#34;) dt.Rows.Add(3, &#34;Suzanne Mathews&#34;, &#34;France&#34;) dt.Rows.Add(4, &#34;Robert Schidner&#34;, &#34;Russia&#34;) Dim result = From rows In dt.AsEnumerable() Group rows By Key = New With {.Name = rows(&#34;Name&#34;), .Country = rows(&#34;Country&#34;)} Into Group Select Group Dim dts As List(Of DataTable) = New List(Of DataTable)() For Each item In result dts.Add(item.CopyToDataTable()) Next</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/127011/Group-By-multiple-Columns-in-DataTable-using-LINQ-in-C-and-VBNet/https://www.aspforums.net:443/Threads/127011/Group-By-multiple-Columns-in-DataTable-using-LINQ-in-C-and-VBNet/Thu, 20 Jun 2019 07:12:22 GMTGroup By multiple Columns in DataTable using LINQ in C# and VB.Net<p>I got the ouput from this.</p> <pre class="brush: csharp">var result = from rows in dt.AsEnumerable() group rows by new { OUTLETNAME = rows[&#34;OUTLET NAME &#34;], Occasion = rows[&#34;Occasion&#34;] } into grp select grp; </pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/127011/Group-By-multiple-Columns-in-DataTable-using-LINQ-in-C-and-VBNet/https://www.aspforums.net:443/Threads/127011/Group-By-multiple-Columns-in-DataTable-using-LINQ-in-C-and-VBNet/Thu, 20 Jun 2019 22:19:52 GMT