Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is it possible to create a datatable from the LINQ?
Message
 
 
À
18/08/2013 22:51:52
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01580581
Message ID:
01580756
Vues:
36
>>>>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!
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform