C# 将两个不同的dataTable合并到一个自定义的dataTable中

[csharp]  view plain  copy
  1. //比较三种情况  
  2.             for (int i = 0; i < dataTable_yh.Rows.Count; i++)  
  3.             {  
  4.                 string vin = dataTable_yh.Rows[i]["VIN"].ToString();  
  5.                 string clxh = dataTable_yh.Rows[i]["CLXH"].ToString();  
  6.                 string rllx = dataTable_yh.Rows[i]["RLLX"].ToString();  
  7.                 DataRow[] dr = dataTable_tg.Select("CLXH='" + clxh + "' AND RLLX='" + rllx + "'");  
  8.             //    //eoor1:不存在  
  9.                 if (dr.Length < 1)  
  10.                 {  
  11.                     dtTable_error.Rows.Add(new object[] { vin, clxh, rllx });  
  12.                 }  
  13.                 else  
  14.                 {  
  15.                     string yh_zczbzl = dataTable_yh.Rows[i]["ZCZBZL"].ToString();  
  16.                     string yh_zhgk = dataTable_yh.Rows[i]["ZHGK"].ToString();  
  17.                     //error2:整车整备质量不一直  
  18.                     if (!yh_zczbzl.Equals(dr[0]["ZCZBZL"]))   
  19.                     {  
  20.                         string tg_zczbzl = dr[0]["ZCZBZL"].ToString();  
  21.                         dtTable_zczbzl.Rows.Add(new object[] { vin, clxh, rllx, yh_zczbzl, tg_zczbzl });  
  22.                     }  
  23.                     //error3:油耗实际值不一致  
  24.                     if (!yh_zhgk.Equals(dr[0]["ZHGK"]))  
  25.                     {  
  26.                         string tg_zhgk = dr[0]["ZHGK"].ToString();  
  27.                         dtTable_zhgk.Rows.Add(new object[] { vin, clxh, rllx, yh_zhgk, tg_zhgk });  
  28.                     }  
  29.                 }  
  30.             }  
[csharp]  view plain  copy
  1. //存入三个页面控件  
  2.             this.gcTable1.DataSource = dtTable_zczbzl;  
  3.             this.gcTable2.DataSource = dtTable_zhgk;  
  4.             this.gcTable3.DataSource = dtTable_error;  
  5.             //比较完初始选中的tab页  
  6.             int selectTabIndex = 1;  
  7.             if (dtTable_zczbzl.Rows.Count < 1)   
  8.             {  
  9.                 selectTabIndex = 2;  
  10.                 if (dtTable_zhgk.Rows.Count < 1)   
  11.                 {  
  12.                     selectTabIndex = 3;  
  13.                     if (dtTable_error.Rows.Count < 1)  
  14.                     {  
  15.                         MessageBox.Show("数据一致");  
  16.                         return;  
  17.                     }  
  18.                 }  
  19.             }  
  20.             xtraTabControl1.SelectedTabPageIndex = selectTabIndex;  

猜你喜欢

转载自blog.csdn.net/shan1774965666/article/details/78050339