How to merge 2 datatable and exclude data

Hi experts

i have 2 database
i make a query on the first and i have, let's say this datatable :

ID (int) | Label (string)

I make another query on the other database and i have this datatable :

ID (int) | Label (string | X (int) | Y (int)


and i want to create a unique dataset or datatable that contains all result from the first datatable without the result of the second datatable based on ID

is it possible?

thank you

regards
LVL 2
Dnx_7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DhaestCommented:
' Assuming you have similar data structures, you can merge the DataTables using
' the DataSet's Merge method, like this:

' Create a DataSet so I can merge the DataTable objects
Dim oDs As New DataSet("MyFunDataSet")
oDs.Tables.Add(sourceTable)
oDs.Merge(destinationTable)

'The Merge method will add the rows to the destimation table if it does not
'find a matching primary key.
0
DhaestCommented:
0
athapaCEO / CTOCommented:
"all result from the first datatable without the result of the second datatable based on ID"

That would be first table by itself.

Did you meant to say, "all results from the second datatable which has same ID as results in first table" ?

Here is a msdn article which talks about join between datatables.
http://support.microsoft.com/kb/325688/en-us

You could also
 1. add both tables to a dataset.
 2. add a new relation between two tables on the ID fields with first table as parent and second as child
 3. iterate all records on first tables
      a. get children records through the relation you created in #2
      b. if the # of children records is > 0 then you find a matching row(s) in the second table

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sognoctCommented:
maybe the better solution is making a query with left / right join that populates a datatable with the results that you want ...
0
DhaestCommented:
>> maybe the better solution is making a query with left / right join that populates a datatable with the
>> results that you want ...

As a remark on this. I see that you use 2 diffent databases... Are they on the same server ? Can you use linked servers ?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.