henryvuong
Member
- Joined
- Sep 8, 2023
- Messages
- 15
- Programming Experience
- 3-5
In my C# code I have two datatable like this:
inventory_table
order_table
I want to substract the quantity of order_table from the inventory_table for the matching SKU, so the result should be:
inventory_table
The rows with SKU "SAM-GAL-S6-64", "IP-13P-128" and "LG-V60-128" now have updated quantity. These tables only exists in memory, not in database, and the result table will be exported to a text file. In reality, inventory_table would have a few thousand rows while order_table has 20-30 rows. Note that the last column of the first table is empty. I believe this task can be done with LINQ. Please advise. Thanks
inventory_table
SKU | Title | Price | Quantity | Handling-Time | |
SAM-GAL-S7-32 | Samsung Galaxy S7 128GB | 300.00 | 5 | ||
SAM-GAL-S6-64 | Samsung Galaxy S6 64GB | 250.00 | 10 | ||
| Samsung Galaxy Note S20 128GB | 275.00 | 7 | ||
IP-13P-128 | Apple iPhone 13 Pro 128GB | 750.00 | 9 | ||
IP-14-128 | Apple iPhone 14 128GB | 800.00 | 4 | ||
IP-12-64 | Apple iPhone 12 64GB | 350.00 | 6 | ||
LG-V60-128 | LG V60 128GB | 250.00 | 3 |
order_table
SKU | Quantity |
SAM-GAL-S6-64 | 2 |
IP-13P-128 | 1 |
LG-V60-128 | 1 |
I want to substract the quantity of order_table from the inventory_table for the matching SKU, so the result should be:
inventory_table
SKU | Title | Price | Quantity | Handling-Time | |
SAM-GAL-S7-32 | Samsung Galaxy S7 128GB | 300.00 | 5 | ||
SAM-GAL-S6-64 | Samsung Galaxy S6 64GB | 250.00 | 8 | ||
| Samsung Galaxy Note S20 128GB | 275.00 | 7 | ||
IP-13P-128 | Apple iPhone 13 Pro 128GB | 750.00 | 8 | ||
IP-14-128 | Apple iPhone 14 128GB | 800.00 | 4 | ||
IP-12-64 | Apple iPhone 12 64GB | 350.00 | 6 | ||
LG-V60-128 | LG V60 128GB | 250.00 | 2 |
The rows with SKU "SAM-GAL-S6-64", "IP-13P-128" and "LG-V60-128" now have updated quantity. These tables only exists in memory, not in database, and the result table will be exported to a text file. In reality, inventory_table would have a few thousand rows while order_table has 20-30 rows. Note that the last column of the first table is empty. I believe this task can be done with LINQ. Please advise. Thanks