c# - converting/Casting ISingleResult - List values to DataTable without Looping -


i using linq sql. when storedprocedure executing result ll returned in form of imultipleresults.

i converting isingleresults , can casted list.

so need convert datatable can bind dataset , pass values ui.

but want such method can convert without loop.

please body me.

for clarification contact me.

thanking you.

first might want see if cast list bindinglist, or this:

bindinglistx = new bindinglist(of elementx)(queryresult.tolist()) 

you might able bind that. if doesn't work though here's question: want not use loop in code @ all, or not see loop in code? possible create extension function conversion:

public static class helperfunctions     {         public static void map<t>(this ienumerable<t> source, action<t> func)         {             foreach (t in source)                 func(i);         }          public static datatable todatatable<t>(this ienumerable<t> source)         {             var dt = new datatable();             var properties = typeof(t).getproperties();             dt.columns.addrange(properties.select(x => new datacolumn(x.name, x.propertytype)).toarray());             source.select(x => dt.newrow().itemarray = properties.select(y => y.getvalue(x, null)).toarray()).map(x => dt.rows.add(x));             return dt;         }     } 

but can see, other extension function 'map' nothing more foreach can used inline. if not want apologize , try come different way.

it worth noting i'm not sure if assigning item array best way populate row if doesn't work please let me know may draft version of function.

hope helps!


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -