标签:
/// <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; }
标签:
原文地址:http://www.cnblogs.com/zhongsq/p/4968099.html