首页 > C# datable去掉重复的行

海潮之声,C# datable去掉重复的行

互联网 2021-02-25 06:35:11

DataTable dt = DbFactory.Instance.GetDbHelp().GetDataTable(sql); // 获取数据源DataTable dt2 = dt.Clone(); // 克隆一个tabledt2.Clear(); // 清理tabledt2.PrimaryKey = new DataColumn[] { dt2.Columns["LAND_TYPE"], dt2.Columns["VILLAGE"], dt2.Columns["COUNTYSIDE"], dt2.Columns["LAND_OWNER"] };foreach (DataRow row in dt.Rows){DataRow srow = dt2.Rows.Find(new object[] { row["LAND_TYPE"].ToString(), row["VILLAGE"], row["COUNTYSIDE"], row["LAND_OWNER"] });if (srow == null){dt2.Rows.Add(row.ItemArray);}else{if (!srow["TFH"].ToString().Contains(row["TFH"].ToString())){srow["TFH"] = srow["TFH"].ToString() + "," + row["TFH"].ToString();}if (!srow["TBH"].ToString().Contains(row["TBH"].ToString())){srow["TBH"] = srow["TBH"].ToString() + "," + row["TBH"].ToString();}if (row["AREA"].ToString() != ""){srow["AREA"] = (Convert.ToDouble(srow["AREA"]) + Convert.ToDouble(row["AREA"])).ToString();}if (row["gy_area"].ToString() != ""){srow["gy_area"] = (Convert.ToDouble(srow["gy_area"] == DBNull.Value ? "0" : srow["gy_area"]) + Convert.ToDouble(row["gy_area"])).ToString();}if (row["jt_area"].ToString() != ""){srow["jt_area"] = (Convert.ToDouble(srow["jt_area"] == DBNull.Value ? "0" : srow["jt_area"]) + Convert.ToDouble(row["jt_area"])).ToString();}

//srow["change_area"] = (Convert.ToDouble(srow["change_area"]) + Convert.ToDouble(row["change_area"])).tostring();//srow["receive_area"] = (Convert.ToDouble(srow["receive_area"]) + Convert.ToDouble(row["receive_area"])).tostring();

}}return dt2;

免责声明:非本网注明原创的信息,皆为程序自动获取自互联网,目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责;如此页面有侵犯到您的权益,请给站长发送邮件,并提供相关证明(版权证明、身份证正反面、侵权链接),站长将在收到邮件24小时内删除。

相关阅读