Combine Two DataTables Into One Datatable

Posted on 2006-05-16
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?

Question by:spgaddipati
    LVL 7

    Accepted Solution

    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
    LVL 6

    Expert Comment

    or if they are matching columns from different tables you can use a union

    FROM Table1
    WHERE Condition = value
    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)
    LVL 13

    Expert Comment

    Doing so in SQL would be preferred.  If not you can do it in code with the DataSet Merge() method.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now