c# - What is best way of filter datatable? -
c# - What is best way of filter datatable? -
in 1 of c# requirement have datatable in having next data
category topics resourceworked tp1 hemant tp2 kevin b tp3 haris b tp4 hemant b tp5 hemant c tp6 kevin
in output want 2 set of data
output-1: each unique category how many resorces worked
category noofresorces 2 b 2 c 1
output-2: how many times resorces worked unquie category like
category resource nooftime hemant 1 kevin 1 b haris 1 b hemant 2 c kevin 1
what best way accomplish output i.e. either datatable filter or linq?
addition: can linq expert tell me online website or book learning linq?
here first requirement:
var uniquecat = d in tbldata.asenumerable() grouping d (string)d["category"] grouping select group; var catres = grp in uniquecat allow c = grp.select(r => r["resourceworked"]).distinct().count() select new {category = grp.key, noofresorces=c}; var summary = cr in catres select string.format("category:{0} count:{1}",cr.category,cr.noofresorces); messagebox.show(string.join(environment.newline,summary));
this sec query:
var uniquecatres = d in tbldata.asenumerable() grouping d new{cat= d["category"], res=d["resourceworked"]} grouping select group; var catrescount = grp in uniquecatres allow category = grp.key.cat allow resource = grp.key.res allow noofresorces = grp.count() select new { category,resource,noofresorces }; summary = crc in catrescount select string.format("category:{0} resource:{1} count:{2}", crc.category,crc.resource, crc.noofresorces); messagebox.show(string.join(environment.newline,summary));
c# linq datatable
Comments
Post a Comment