.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Forum >> LINQ >> Post New QuestionBookmark and Share Subscribe to Forum

Inner join of two datatables using linq

Posted By: Maverick     Posted Date: July 12, 2011    Points:5   Category :LINQ
How to apply inner join on two datatables and het the result in the third datatable using LINQ?

Author: Ravi Ranjan Kumar          Accepted Answer   
Posted Date: July 12, 2011     Points: 40   


DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();

// Here assumed both the datable are filled with some data
// Below linq query joins two table based on ID column and gets the resultset

DataTable result = (from t1 in dt1.AsEnumerable()
join t2 in dt2.AsEnumerable() on t1.Field<int>("id") equals t2.Field<int>("id")
select t1).CopyToDataTable();

or have a read thread of "Create combined DataTable from two DataTables joined with LINQ"

Thanks & Regards
Ravi Ranjan Kumar

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend