Reputation: 5631
I have a problem in which I have to copy data from DataTable to another , both have different structure , thats why i cant just call rowImport method.
In my previous post I had asked what will be an optimized way to do this job and i was suggested that i should look into adapter pattern ?
IEnumerable<DataRow> query = from vendInv in
VendorInvoiceStagingTable.AsEnumerable()
where vendInv.Field<string>(VendInvoice.Number) == InvoiceHeader
select vendInv;
Object[] obj = new Object[10];
var item = query.First();
for (int idx = 0; idx < 10; idx++)
{
obj[idx] = item[idx];
}
VendorInvoiceTable.Rows.Add(obj);
Complete problem is describe on the following link :
Best way to copy Data from one DataTable to another DataTable with diffrent structure
QUESTION : How can i resolve this problem using Adapter pattern ?
Upvotes: 0
Views: 755
Reputation: 5312
What about Merge? Which will "Merge the specified System.Data.DataTable with the current System.Data.DataTable."
Upvotes: 0
Reputation: 632
I dont think that Adapter pattern can help you in any way here. My guess is that you havent decided for DataTable as your datastructure by yourself but some other circumstances like other component in your applciation that consumes it (UI?) forced you to use it. This means that these components cal only "talk" to DataTable interface. Adapter pattern is about intermediate interface between consumer (client) and the source (adaptee). The intermediate interface is called Adapter. So stick with simplest possible solution. From your example i have the feeling that your mapping is simple 1:1 row "conversion" and it doesnt make much sense to introduce any hardcore patterns here :)
Upvotes: 3