There is one .cs for converting linq to datatable //.cs file using System; using System.Collections.Generic; using System.Text; using System.Reflection; using System.Data; public class LinqToDataTable { public static DataTable ObtainDataTableFromIEnumerable(System.Collections.IEnumerable ien) { DataTable dt = new DataTable(); try { foreach (object obj in ien) { Type t = obj.GetType(); PropertyInfo[] pis = t.GetProperties(); if (dt.Columns.Count == 0) { foreach (PropertyInfo pi in pis) { if (pi.PropertyType.Name == "Nullable`1") { string str = pi.PropertyType.FullName; str = str.Replace("System.Nullable`1", ""); str = str.Substring(str.IndexOf("System")); str = str.Substring(0, str.IndexOf(",")); dt.Columns.Add(pi.Name, str.GetType()); } else dt.Columns.Add(pi.Name, pi.PropertyType); } } DataRow dr = dt.NewRow(); foreach (PropertyInfo pi in pis) { object value = pi.GetValue(obj, null); dr[pi.Name] = value; } dt.Rows.Add(dr); } } catch (Exception) { dt = null; } return dt; } } //DataTable dtEmployees = LinqToDataTable.ObtainDataTableFromIEnumerable((IEnumerable)employees); now assign the datatable in dataview
Padmanabhan