var list1 = (from t1 in dataTable1.AsEnumerable()
select new
{
Key1 = t1.Field<int>("Key1"),
Key2 = t1.Field<int>("Key2"),
A = t1.Field<string>("A"),
B = t1.Field<string>("B")
});
var list2 = (from b in dataTable2.AsEnumerable()
select new
{
Key1 = b.Field<int>("Key1"),
Key2 = b.Field<int>("Key2"),
X = b.Field<string>("X"),
Y = b.Field<string>("Y")
});
// Now join the 2 collections and get the result you want.
var result = (from x in list1
join y in list2 on new { x.Key1,x.Key2} equals new { y.Key1,y.Key2 }
select new { A = x.A, X = y.X }).ToList();
假設鍵1和鍵2是int
型和A·B,X和Y是string
型。
你可以把數據放在你的數據表中嗎?對不起,我還沒有完全遵循 – Shyju
也許一個T-SQL的例子說明你如何在數據庫中做到這一點,這將有助於理解問題並闡明答案。 – CodingGorilla
@Shyju我在上面,還沒有找到正確格式化的方法。 – Iason