我有兩個Table1和Table2,其列的值如下: 這兩個表: 我想更新Table1中的「PaidAmount」。根據兩個表中的「InvoiceNo」列加入。加入並更新數據表
表1:
InvoiceNo Vendor InvoiceValue InvoiceDate PaidAmount
--------- ------ ------------- ----------- ----------
1 AA 15000 01 Dec 2013 0
2 BB 20000 10 Dec 2013 0
3 CC 10000 18 Dec 2013 0
表2:
VoucherNo Date InvoiceNo Amount
------- ----------- ---------- ------
001 01 Nov 2013 1 5000
002 10 Nov 2013 2 6000
003 20 Nov 2013 3 7000
001 02 Nov 2013 1 2000
我想要的數據表應該是這樣的:
DesiredTable:
InvoiceNo Vendor InvoiceValue InvoiceDate PaidAmount
--------- ------ ------------- ----------- ----------
1 AA 15000 01 Dec 2013 7000
2 BB 20000 10 Dec 2013 6000
3 CC 10000 18 Dec 2013 7000
如何實現這個結果? 我已經嘗試了下面的一個。
Table1.AsEnumerable().Join(Table2.AsEnumerable(),
dt1_Row => dt1_Row.ItemArray[0],
dt2_Row => dt2_Row.ItemArray[2],
dt1_Row, dt2_Row) => new { dt1_Row, dt2_Row }
).ToList()
.ForEach(o => o.dt1_Row.SetField(4, o.dt2_Row.ItemArray[3]));
但它給出結果作爲
InvoiceNo Vendor InvoiceValue InvoiceDate PaidAmount
--------- ------ ------------- ----------- ----------
1 AA 15000 01 Dec 2013 2000
2 BB 20000 10 Dec 2013 6000
3 CC 10000 18 Dec 2013 7000
如何獲得我想要的表?
它給出了錯誤:不能隱式地將類型'object'轉換爲'decimal'。 – thevan
我已經更新了從對象到int的轉換代碼。字段金額的類型是什麼? –
decimal是數量和paidamount的數據類型。 – thevan