判断datatable指定列是否重复
var query = from t in dtTemp.AsEnumerable()
group t by new { t1 = t.Field<string>("StartTime"), t2 = t.Field<string>("EndTime"), t3 = t.Field<string>("AreaID"), t4 = t.Field<string>("WeightforStart"), t5 = t.Field<string>("WeightforEnd"), t6 = t.Field<string>("NumberPlusIncome"), t7 = t.Field<string>("KgPlusIncome"), t8 = t.Field<string>("JinWeiZhi"), t9 = t.Field<string>("DestinationSite") } into m
select new
{
StartTime = m.Key.t1,
EndTime = m.Key.t2,
AreaID = m.Key.t3,
WeightforStart = m.Key.t4,
WeightforEnd = m.Key.t5,
NumberPlusIncome = m.Key.t6,
KgPlusIncome = m.Key.t7,
JinWeiZhi = m.Key.t8,
DestinationSite = m.Key.t9,
rowcount = m.Count()
};
foreach (var q in query)
{
if (q.rowcount > 1)
{
string ProvinceName = "";
string CityName = "";
if (q.AreaID!="")
{
FreightMaintain f = new FreightMaintain();
f.AreaID = q.AreaID;
DataTable dta = bll.SeleteAreaID2(f);
ProvinceName = dta.Rows[0]["ProvinceName"].ToString();
CityName = dta.Rows[0]["CityName"].ToString();
}
DataTableHelper.AddErrorRow(errdt, 0, "重复列:有效期起" + q.StartTime + " ,有效期止" + q.EndTime + ",目的地省" + ProvinceName + ",目的地市" + CityName + ",目的地站点" + q.DestinationSite + ",重量段起(不含)" + q.WeightforStart + ",重量段止(含)" + q.WeightforEnd + ",单票加收" + q.NumberPlusIncome + ",每公斤加收" + q.KgPlusIncome + ",进位值" + q.JinWeiZhi + "");
}
}