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


Top 5 Contributors of the Month
david stephan

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?

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

Try

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"
http://stackoverflow.com/questions/2379747/create-combined-datatable-from-two-datatables-joined-with-linq-c

Thanks & Regards
Ravi Ranjan Kumar
http://raviranjankr.wordpress.com


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
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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