Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is it possible to create a datatable from the LINQ?
Message
 
 
To
18/08/2013 22:51:52
John Baird
Coatesville, Pennsylvania, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01580581
Message ID:
01580756
Views:
37
>>>>I can not convert row into DataRow, therefore I don't see a way to access each individual column of that resulting query. David's class solves this problem, but if I can create a simpler code, I'd love to.
>>>
>>>
>>>I haven't tried with anonymous types, I mostly use concrete classes to select into. But through reflection you can enumerate the fields & properties in the object and then create the Data table based on these..... If the extension method works for you and creates what you need, this will probably be the simplest solution going forward...
>>
>>Yes, that class does work.
>>
>>But I found (actually, David replied in my e-mail) that I can use properties of this anonymous type.
>>
>>So, looks like I can simply use code like this
>>
>>
>>foreach (var row in resultingQuery)
>>                     {
>>                        DataRow newRow = dtReturn.NewRow();
>>
>>                        newRow["resource1"] = row.resource1;
>>                        newRow["fname"] = row.fname;
>>
>>                        dtReturn.Rows.Add(newRow);
>>                     }
>>
>>
>>Wondering if this is easier than David's class or not.
>
>For me, I would roll my own as you have demonstrated. But I would implement it as an extension method.

I like this reply!
Previous
Reply
Map
View

Click here to load this message in the networking platform