Hi,
Use your datasource to find the solution. Try this:
DataTable tblTest= new DataTable();
tblTest.Columns.Add("ProductName", typeof(string));
tblTest.Columns.Add("Price ", typeof(double));
tblTest.Rows.Add("Pen", 10.00);
tblTest.Rows.Add("Paper", 12.00);
tblTest.Rows.Add("Pen", 10.00);
tblTest.Rows.Add("ColorBrush", 5.00);
var query = from row in tblTest.AsEnumerable()
group row by row.Field<string>("ProductName") into Products
orderby Products.Key
select new
{
ProductName = Products.Key,
ProductCount = Products.Count()
};
Hereafter you can print your records
foreach (var Prod in query)
{
Console.WriteLine("{0}\t{1}", Prod.ProductName, Prod.ProductCount);
}
Your output will be like:
Pen 2
Paper 1
ColorBrush 1
--Amit