要求:
1.两表结果相同(一个人是历史数据,一个是现网数据)
2.将现网数据与历史数据进行比较,将存在差异的数据列出来。返回需要databtalbe.
3.由于数据访问层封装好了,所以不能用SQL来实现。
4.可以由对方提供方法得到 A,和B表数据
5。现在我要的操作是,对两表进行对比(一行一行对比吗?),建一新表,将对比后组织成新表返回结果。a 表 
id name 
1    a 
2    b 
3    c 
b 表 
id name 
1    c 
2    b 
3    a 
要的结果: 
a.id  a.name  b.id  b.name 
1       a      1     c 
3       c      3     a

解决方案 »

  1.   

    DataTable dt1=new DataTable(); 
    dt1.Columns.Add("ID",typeof(int)); 
    dt1.Columns.Add("Name",typeof(string)); 
    dt1.PrimaryKey=new DataColumn[] { dt1.Columns[0] }; DataTable dt2=new DataTable(); 
    dt2.Columns.Add("ID",typeof(int)); 
    dt2.Columns.Add("MC",typeof(string));DataTable dt3= dt1.Copy(); 
    dt3.Merge(dt2); 
    DataTable curDt = dt2.Copy(); //curDt存放合并后的值 
    if(!curDt.Columns.Cotains("B")) curDt.Columns.Add("B"); for(int r = 0; r < dt2.Rows.Count; r++) 

    DataRow dr = dt2.Rows[r]; 
    string aValue = dr["A"].ToString().ToUpper(); 
    foreach(DataRow tDr in dt1.Rows) 

    string tValue = tDr["A"].ToString().ToUpper(); 
    if(tValue == aValue) 

    curDt.Rows[r]["B"] = tDr["B"]; 
    break;