DataTable orders = ds.Tables["SalesOrderHeader"]; var ordersQuery = orders.ToQueryable();where does "ToQueryable()" come from? I checked the documentation and didn't see that method associated with a DataTable, as you're using it. Perhaps that's part of Kevin's extension method, but I don't see it in the code you posted either. Did I miss something or did you leave out some of the code? Do you have a link to the article or blog where Kevin posted this?
> >// Take the anonymous type result "NewResult" and convert it to a DataTable > >DataTable dtResults = NewResult.ToADOTable( rec => new object[] {NewResult}); > > >public static class VarToTable >{ > public static DataTable ToADOTable<T>( > this IEnumerable<T> varlist, CreateRowDelegate<T> fn) > { > DataTable dtReturn = new DataTable(); > // Could add a check to verify that there is an element 0 > T TopRec = varlist.ElementAt(0); > > // Use reflection to get property names, to create table > // column names > PropertyInfo[] oProps = ((Type)TopRec.GetType()).GetProperties(); > foreach (PropertyInfo pi in oProps) > dtReturn.Columns.Add(pi.Name, pi.PropertyType); > foreach (T rec in varlist) > { > DataRow dr = dtReturn.NewRow(); > foreach (PropertyInfo pi in oProps) > dr[pi.Name] = pi.GetValue(rec, null); > dtReturn.Rows.Add(dr); > } > return (dtReturn); > } > public delegate object[] CreateRowDelegate<T>(T t); >} >>
>DataTable orders = ds.Tables["SalesOrderHeader"]; > >var ordersQuery = orders.ToQueryable(); > >var query = from o in ordersQuery > where o.Field<bool>("OnlineOrderFlag") == true > select new { SalesOrderID = o.Field<int>("SalesOrderID"), OrderDate = o.Field<DateTime>("OrderDate") }; > >dtResults = query.ToADOTable( rec => new object[] {query}); >>