How to convert IEnumerable DataRow to DataTable RRS feed

  • Question

  •  IEnumerable<DataRow> query =
                             (from r in objEmpEntities.Employees.AsEnumerable()
                              where (r.Age > 22)
                              select r).Cast<DataRow>();
                DataTable dt = query.CopyToDataTable<DataRow>();

    Getting this Exception

    An exception of type 'System.InvalidCastException' occurred in System.Core.dll but was not handled in user code

    Additional information: Unable to cast object of type 'ConvertIEnumerableDataRowtoDataTable.Employee' to type 'System.Data.DataRow'.

    Wednesday, June 17, 2015 1:31 AM


All replies