views:

32

answers:

1
            var dept_list = (from map in DtMapGuestDepartment.AsEnumerable()
                            where map.Field<Nullable<long>>("GUEST_ID") == DRowGuestPI.Field<Nullable<long>>("PK_GUEST_ID")
                            join
                            dept in DtDepartment.AsEnumerable()
                            on map.Field<Nullable<long>>("DEPARTMENT_ID") equals dept.Field<Nullable<long>>("DEPARTMENT_ID")
                            select new 
                                {
                                    dept_id=dept.Field<long>("DEPARTMENT_ID")
                                    ,dept_name=dept.Field<long>("DEPARTMENT_NAME")
                                }).Distinct();


            DataTable dt = new DataTable();
            dt.Columns.Add("DEPARTMENT_ID");
            dt.Columns.Add("DEPARTMENT_NAME");
            foreach (long? dept_ in dept_list)
            {
                dt.Rows.Add(dept_[0], dept_[1]);
            }

EDIT

In the previous question asked by me.

I got an answer like this for single value. What is the difference between the two ?

foreach (long? dept in dept_list) {
    dt.Rows.Add(dept);
}
+1  A: 
foreach (var dept_ in dept_list)
{
   dt.Rows.Add(dept_.dept_id, dept_dept_name);
}

answer for EDIT

I guess that in your previous question dept_list was of type IEnumerable but in this question it is of type IEnumerable where T is an anonymous type

Itay