0
votes

I'm new to DataTables and need a bit of help, specifically with the Merge method.

I have a WPF application where my UI elements are bound to various columns in a 1-row DataTable. There are many columns. I have a thread which is receiving a serialized DataTable object from MSMQ, de-serializing it, then replacing the single row in my DataTable with the new row, thus updating values in the bound controls (after resetting the DataContext). So far this is working fine.

Now there is a requirement to poll 2 different MSMQ queues, each with their own data, then refresh my DataTable with both. So here is my issue:

Situation:
I have MainTable with columns IDCol, Col1, Col2, Col3, Col4.
Process 1 returns a NewTable with IDCol, Col1, Col2.
Process 2 returns a NewTable with IDCol, Col3, Col4.
In all cases, IDCol is primary key and will have same value.
Each process is running in its own thread (actually, BackgroundWorker).

Can I use DataTable.Merge(NewTable) in each thread, and will they properly merge the various columns, instead of the old method of deleting a row and adding a new one?

Thanks...

1

1 Answers

0
votes

I was able to figure this out myself. As long as the primary key field of each datatable returned matches the primary key field of my main record, the merge just works as advertised. Thanks anyway...