微博:https://weibo.com/6274976536/profile?rightmod=1&wvr=6&mod=personinfo&is_all=1
注:需引用system.linq;
解析:
1. dt 即为数据源,需要对其某列分组的DataTable;
2. var queryFee = from t in dt.AsEnumerable()
group t by new { t1 = t.Field<string>("fee") } into m
select new
{
fee = m.Key.t1,
};//house = m.First().Field<string>("fee")
from ... in ..... group .... by new {......} into ... select new {......} 为固定句式
3. string strFee = string.Empty;
foreach (var item in queryFee.ToList())
{
strFee += string.Format("'{0}',", item.fee);
}
queryFee.ToList() 即为按某列分组后的列表,循环获取数据,item.fee 即为列表中当前项fee的值;