/// <summary> /// 检查准备插入的表头DT内的行记录是否已在AkzoFormula表内存在,若存在,即删除 /// </summary> /// <returns></returns> private DataTable Checkdt(DataTable dt, string macadd) { var removeList = new List <DataRow>(); try { var searchData = new SearchData(); //根据指定条件获取AkzoFormula表记录 var searchdt = searchData.SearchFormulaList(macadd); //当查询AkzoFormula表有记录时才执行 if (searchdt.Rows.Count > 0) { for (var i = 0; i < dt.Rows.Count; i++) { var row = searchdt.Select("Factory = '" + dt.Rows[i][0] + "' and ColorCode = '" + dt.Rows[i][1] + "'"); //将重复的记录放到removeList内(在后面用于循环删除) if (row.Length > 0) { removeList.Add(dt.Rows[i]); } } } //将整理出来的重复行通过循环进行删除 for (var j = 0; j < removeList.Count; j++) { dt.Rows.Remove(removeList[j]); } } catch (Exception ex) { throw new Exception(ex.Message); } return(dt); }