Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27336

VS 2010 Merging / union two data tables with same columns

$
0
0
Hi there...

I'm still learning about data tables so I hope somebody can assist....and assume I know nothing :)

I have a dataset with a datatable defined. I'll just say Dataset1 and datatable1 with all the columns made in the dataset.

I create a new instance of datatable1 called "dtsale" and fill it with data using an SQL query.

I create a new instance of datatable1 called "dtcanc" and fill it with data using an SQL query.

I then do some calculations in .NET on a column in the datatable in a column called STATUS

eg.
dtsale.Columns("STATUS").Expression = "'SALE'"
dtcanc.Columns("STATUS").Expression = "'CANC'"

.. I have these two tables, with same columns.. I want to do a merge / union so one set of data is placed below the other. I then put the datatable into Excel.

I can get it into Excel no problem using dtsale or dtcanc but not the two together.

below is code I have tried but it's not right.

Code:

        dtcanc.Merge(dtsale)
Any help is appreciated. Doing the UNION in SQL before I put into a datatable isn't an option for me on this occasion due to some other calculations I'm doing before the merge.

Kind Regards

Viewing all articles
Browse latest Browse all 27336

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>