Please find the Solution, Tested its working.
static void Main(string[] args)
{
DataTable table = new DataTable();
table.Columns.Add("ID", typeof(string));
table.Columns.Add("value", typeof(double));
table.Rows.Add("aa", 1);
table.Rows.Add("aa", 1);
table.Rows.Add("aa", 1);
table.Rows.Add("bb", 1);
table.Rows.Add("bb", 1);
table.Rows.Add("bb", 1);
table.Rows.Add("bb", 1);
table.Rows.Add("cc", 1);
var tblData = from rowData in table.AsEnumerable()
where rowData.Field<string>("ID") == "aa"
select rowData;
Console.WriteLine("ID" + " : " + "value");
Console.WriteLine("------------");
foreach (var item in tblData)
{
Console.WriteLine(item.Field<string>("ID").ToString() + " : " + item.Field<double>("value").ToString());
}
Console.WriteLine("\n\n");
var tblDatas = from rowData in table.AsEnumerable()
group rowData by rowData.Field<string>("ID") into groupResult
where groupResult.Count() == 3
select new { ID = groupResult.Key, value = groupResult };
Console.WriteLine("ID Value with 3 Rows" );
Console.WriteLine("------------");
foreach (var item in tblDatas)
{
Console.WriteLine(item.ID);
}
Console.ReadLine();
}
If you are expecting more, let me know what you are exactly required. I used Linq query here to fetch the data from DataTable.
Thanks!