C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » General »

Join dictionary and datatable using LINQ


Posted Date: 05 Oct 2009    Resource Type: Code Snippets    Category: General
Author: Sudeep SyamnathMember Level: Silver    
Rating: 1 out of 5Points: 5



Hello All,

The code snippet joins a dictionary object and a datatable. Both objects have a common field named CusID. Dictionary object's key has the CusIDs and datatable has a column named CusID. The joining needs to be done based on the same.

Step 1
Create a dictionary object and add items

oDic.Add("001", "Customer1");
oDic.Add("002", "Customer2");


Step 2
Create a datatable and fill values

DataTable otbl = new DataTable();
otbl.Columns.AddRange(new DataColumn[2] { new DataColumn("CusID"), new DataColumn("Col2") });
DataRow drNew = otbl.NewRow();
drNew["CusID"] = "001";
drNew["Col2"] = "Good Work";
otbl.Rows.Add(drNew);

drNew = otbl.NewRow();
drNew["CusID"] = "002";
drNew["Col2"] = "Poor";
otbl.Rows.Add(drNew);


Step 3
Write the LINQ

var result = from myt in otbl.AsEnumerable()
join myd in oDic
on myt.Field("CusID") equals myd.Key
select new { Col2 = myt.Field("Col2"),
CusID = myt.Field("CusID")
};

Best Regards,
Sudeep Syamnath



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Join dictionary and datatable using LINQ  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Typing Contents in Ms Word from DotNet Applications
Previous Resource: Title case of a string
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use