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
|
No responses found. Be the first to respond and make money from revenue sharing program.
|