Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Get Distinct value using Group By , Having , Count in DataTable C#
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Data; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here Console.WriteLine("Hello, world!"); // this is your datatable DataTable table = new DataTable(); table.Columns.Add("Salesman", typeof(string)); table.Columns.Add("ClientID", typeof(int)); //insert your data table.Rows.Add("Bob", 1); table.Rows.Add("Bob", 2); table.Rows.Add("Bob", 3); table.Rows.Add("Tom", 4); table.Rows.Add("Joe", 5); //table.Rows.Add("Joe", 6); table.Rows.Add("Tim", 7); //table.Rows.Add("Tim", 8); // query with LINQ var query = from row in table.AsEnumerable() group row by row.Field<string>("Salesman") into sales where sales.Count() > 1 select new { Name = sales.Key, CountOfClients = sales.Count() }; // print result foreach (var salesman in query) { Console.WriteLine("{0}\t{1}", salesman.Name, salesman.CountOfClients); } } } }
run
|
edit
|
history
|
help
0
Z_non_pow
delete_xml_empty_tags
jkkjhkjhk
Ok
Captcha
multi variable random number generator
a6
adxcsdxsddxsd
IMT
.net Q4