Я получил два файла Excel из пользовательской загрузки, используя OleDb. Я имел следующий результат:
| Location | Item Type | AmountA | AmountB | Type |
| A | A | 5 | 4 | |
Но я хочу получить следующий результат:
| Location | Item Type | AmountA | AmountB | Type |
| A | A | 5 | | A |
| A | A | | 4 | B |
Вот мои коды:
public DataTable CombineofAdjustmentNTransaction(DataTable A, DataTable B)
{
DataTable TableE = new DataTable();
TableE.Columns.Add(new DataColumn("Location"));
TableE.Columns.Add(new DataColumn("Item Type"));
TableE.Columns.Add(new DataColumn("AmountA)"));
TableE.Columns.Add(new DataColumn("AmountB"));
TableE.Columns.Add(new DataColumn("TransactionType"));
foreach (DataRow dtE in A.Rows)
{
foreach (DataRow rowB in B.Rows)
{
if (rowB["Location"].ToString() == dtE["Location"].ToString() && rowB["Item Type"].ToString() == dtE["Item Type"].ToString()
)
{
var newRow = TableE.NewRow();
newRow["Location"] = dtE["Location"];
newRow["Item Type"] = dtE["Item Type"];
if(dtE["Type"].ToString() == "GRN")
{
newRow["AmountA"] = dtE["AmountA"];
newRow["Type"] = "GRN";
}
if (rowB["Type"].ToString() == "STK_ADJ")
{
newRow["AmountB"] = rowB["AmountB"];
newRow["Type"] = "STK_ADJ";
}
TableE.Rows.Add(newRow);
}
}
}
return TableE;
}
}
Пожалуйста, помогите спасибо!