?
Solved

Combine Two DataTables Into One Datatable

Posted on 2006-05-16
3
Medium Priority
?
1,282 Views
Last Modified: 2008-02-01
Hi I have Two Data Tables derived from two different sql queries.

I need to combine them into one dataTable so that new datatable can be assigned as datasource to the datagrid.

Is it possible?

Thanks
Siva.
0
Comment
Question by:spgaddipati
3 Comments
 
LVL 7

Accepted Solution

by:
pauljk1619 earned 100 total points
ID: 16692324
you can do an inner join between the SQL statements....

this is a SQL Server syntax example.

Select * from (Select * from TugOrder where TugOrderID < 500) as A Inner Join (Select * from TugsInOrder) As B on A.TugOrderID=B.TugOrderID
0
 
LVL 6

Expert Comment

by:PoeticAudio
ID: 16692530
or if they are matching columns from different tables you can use a union

SELECT
     A,
     B,
     C
FROM Table1
WHERE Condition = value
UNION
SELECT
    D,
    E,
    F
FROM Table2
WHERE Condtion = value

but the type of A must match D, B's type must match E and C's must match F (by type I mean DateTime, varchar...etc

This works if you're selecting similar data from 2 different tables and you want to merge it all together. For example if you have Name, Address, Phone in Customers that you want to merge with Name, Address, Phone in an Employee table (or something, not the best example, but hey)
0
 
LVL 13

Expert Comment

by:devsolns
ID: 16692641
Doing so in SQL would be preferred.  If not you can do it in code with the DataSet Merge() method.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question