我有两个不同的数据表
datatable1: customer, product, shippedqty
datatable2: customer, product, febforecast, marforecast, aprforecast
此处客户和产品列相同
我需要在datatable1
和datatable2
列上将customer
与products
进行比较,我需要将结果集设置为新的datatable
customer,product,dhipedqty,febforecast,marforecast,aprforecast
这就是我尝试过的:
var tablesJoinend = from t1 in dt.Rows.Cast<DataRow>()
join t2 in forecastdatatable.Rows.Cast<DataRow>()
on new { A = t1["Customer"].ToString(), B = t1["ProductCode"].ToString() }
equals new { A = t2["customer"].ToString(), B = t2["NDC"].ToString() }
select t1;
现在我尝试了这个没有用的
var results = from t1 in dt.Rows.Cast<DataRow>()
join t2 in forecastdatatable.Rows.Cast<DataRow>() on new { A = t1["Customer"].ToString(), B = t1["ProductCode"].ToString() } equals new { A = t2["customer"].ToString(), B = t2["NDC"].ToString() }
select new
{
CustID = Convert.ToInt32(t1["Customer"]),
ColX = Convert.ToInt32(t1["ProductCode"]),
ColY = Convert.ToInt32(t1[3]),
a = Convert.ToInt32(t1[4]),
xx = Convert.ToInt32(t2[4]),
qq = Convert.ToInt32(t2[5])
};