/// <summary> /// 兩個dt比較 B與A相同列相同值的從新更新到B /// </summary> /// <param name="dtA">總的dt(數據均爲0)</param> /// <param name="dtB">當前dt(已經查詢到的數據)</param> /// <returns>dtA</returns> private DataTable CompareDataTable(DataTable dtA, DataTable dtB) { for (int i = 0; i < dtB.Rows.Count; i++) { for (int j = 0; j < dtB.Columns.Count; j++) { string categorynameB = Convert.ToString(dtB.Rows[i]["categoryname"]); //行業 for (int k = 0; k < dtA.Rows.Count; k++) { for (int m = 0; m < dtA.Columns.Count; m++) { string categorynameA = Convert.ToString(dtA.Rows[k]["categoryname"]); //行業 if (categorynameB == categorynameA) { string ColumnsB = dtB.Columns[j].ToString(); string ColumnsA = dtA.Columns[m].ToString(); if (ColumnsB == ColumnsA) { dtA.Rows[k][m] = dtB.Rows[i][j]; } } } } } } return dtA; }